summaryrefslogtreecommitdiff
path: root/src/gui.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2004-10-11 10:06:20 +0000
committerBram Moolenaar <Bram@vim.org>2004-10-11 10:06:20 +0000
commit7171abea1ad8d33cce89a9664873417187139a53 (patch)
tree491426309f8e38304d96b55b7ac5ab6bdaefcc6b /src/gui.c
parent349b2f643a5e840facf42942d37d47c5b37c1292 (diff)
downloadvim-7171abea1ad8d33cce89a9664873417187139a53.zip
updated for version 7.0018
Diffstat (limited to 'src/gui.c')
-rw-r--r--src/gui.c77
1 files changed, 46 insertions, 31 deletions
diff --git a/src/gui.c b/src/gui.c
index 9b33f9d39..71b738ced 100644
--- a/src/gui.c
+++ b/src/gui.c
@@ -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(&regmatch, 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 */