diff options
author | Bram Moolenaar <Bram@vim.org> | 2004-10-11 10:06:20 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2004-10-11 10:06:20 +0000 |
commit | 7171abea1ad8d33cce89a9664873417187139a53 (patch) | |
tree | 491426309f8e38304d96b55b7ac5ab6bdaefcc6b /src/gui.c | |
parent | 349b2f643a5e840facf42942d37d47c5b37c1292 (diff) | |
download | vim-7171abea1ad8d33cce89a9664873417187139a53.zip |
updated for version 7.0018
Diffstat (limited to 'src/gui.c')
-rw-r--r-- | src/gui.c | 77 |
1 files changed, 46 insertions, 31 deletions
@@ -4411,9 +4411,8 @@ no_console_input() } #endif -#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MOTIF) \ - || defined(MSWIN_FIND_REPLACE) || defined(FEAT_SUN_WORKSHOP) \ - || defined(PROTO) || defined(FEAT_GUI_KDE) +#if defined(FIND_REPLACE_DIALOG) || defined(FEAT_SUN_WORKSHOP) \ + || defined(PROTO) /* * Update the current window and the screen. */ @@ -4430,8 +4429,7 @@ gui_update_screen() } #endif -#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MOTIF) \ - || defined(MSWIN_FIND_REPLACE) || defined(PROTO) || defined(FEAT_GUI_KDE) +#if defined(FIND_REPLACE_DIALOG) || defined(PROTO) static void concat_esc __ARGS((garray_T *gap, char_u *text, int what)); /* @@ -4539,28 +4537,10 @@ gui_do_findrepl(flags, find_text, repl_text, down) int i; int type = (flags & FRD_TYPE_MASK); char_u *p; + regmatch_T regmatch; ga_init2(&ga, 1, 100); - - if (type == FRD_REPLACE) - { - /* Do the replacement when the text under the cursor matches. */ - i = STRLEN(find_text); - p = ml_get_cursor(); - if (((flags & FRD_MATCH_CASE) - ? STRNCMP(p, find_text, i) == 0 - : STRNICMP(p, find_text, i) == 0) - && u_save_cursor() == OK) - { - /* A button was pressed thus undo should be synced. */ - if (no_u_sync == 0) - u_sync(); - - del_bytes((long)i, FALSE); - ins_str(repl_text); - } - } - else if (type == FRD_REPLACEALL) + if (type == FRD_REPLACEALL) ga_concat(&ga, (char_u *)"%s/"); ga_concat(&ga, (char_u *)"\\V"); @@ -4579,21 +4559,56 @@ gui_do_findrepl(flags, find_text, repl_text, down) if (type == FRD_REPLACEALL) { - /* A button was pressed, thus undo should be synced. */ - if (no_u_sync == 0) - u_sync(); - ga_concat(&ga, (char_u *)"/"); concat_esc(&ga, repl_text, '/'); /* escape slashes */ ga_concat(&ga, (char_u *)"/g"); - ga_append(&ga, NUL); + } + ga_append(&ga, NUL); + + if (type == FRD_REPLACE) + { + /* Do the replacement when the text at the cursor matches. Thus no + * replacement is done if the cursor was moved! */ + regmatch.regprog = vim_regcomp(ga.ga_data, RE_MAGIC + RE_STRING); + regmatch.rm_ic = 0; + if (regmatch.regprog != NULL) + { + p = ml_get_cursor(); + if (vim_regexec_nl(®match, p, (colnr_T)0) + && regmatch.startp[0] == p) + { + /* Clear the command line to remove any old "No match" + * error. */ + msg_end_prompt(); + + if (u_save_cursor() == OK) + { + /* A button was pressed thus undo should be synced. */ + if (no_u_sync == 0) + u_sync(); + + del_bytes((long)(regmatch.endp[0] - regmatch.startp[0]), + FALSE); + ins_str(repl_text); + } + } + else + MSG(_("No match at cursor, finding next")); + vim_free(regmatch.regprog); + } + } + + if (type == FRD_REPLACEALL) + { + /* A button was pressed, thus undo should be synced. */ + if (no_u_sync == 0) + u_sync(); do_cmdline_cmd(ga.ga_data); } else { /* Search for the next match. */ i = msg_scroll; - ga_append(&ga, NUL); do_search(NULL, down ? '/' : '?', ga.ga_data, 1L, SEARCH_MSG + SEARCH_MARK); msg_scroll = i; /* don't let an error message set msg_scroll */ |