diff options
-rw-r--r-- | runtime/doc/vim_diff.txt | 1 | ||||
-rw-r--r-- | src/nvim/ex_cmds.c | 69 | ||||
-rw-r--r-- | test/functional/ui/incsubstitute_spec.lua | 28 |
3 files changed, 49 insertions, 49 deletions
diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index 9b862275cc..80db8eefb0 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -134,7 +134,6 @@ Events: |TextYankPost| Highlight groups: - |hl-Substitute| |hl-QuickFixLine| |hl-Substitute| |hl-TermCursor| diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index ca02bb68de..6d4533f318 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -3946,42 +3946,28 @@ skip: // Show 'incsubstitute' preview if there are matched lines. buf_T *incsub_buf = NULL; - if (matched_lines.size != 0 && pat != NULL && *p_ics != NUL && eap->is_live) { - // Place cursor on the first match after the cursor. - // If all matches are before the cursor, then do_sub already placed the - // cursor on the last match. - - linenr_T cur_lnum = 0; + if (eap->is_live && matched_lines.size != 0 && pat != NULL && *p_ics != NUL) { + // Place cursor on the first match after the cursor. (If all matches are + // above, then do_sub already placed cursor on the last match.) colnr_T cur_col = -1; - MatchedLine current; - - for (size_t j = 0; j < matched_lines.size; j++) { - current = matched_lines.items[j]; - cur_lnum = current.lnum; - - // 1. Match on line of the cursor, need to iterate over the - // matches on this line to see if there is one on a later - // column - if (cur_lnum == old_cursor.lnum) { - for (size_t i = 0; i < current.cols.size; i++) { - if (current.cols.items[i] >= old_cursor.col) { - cur_col = current.cols.items[i]; + MatchedLine curmatch; + for (size_t j = 0; j < matched_lines.size && cur_col == -1; j++) { + curmatch = matched_lines.items[j]; + if (curmatch.lnum == old_cursor.lnum) { + // On cursor line; iterate in-line matches to find one after cursor. + for (size_t i = 0; i < curmatch.cols.size; i++) { + if (curmatch.cols.items[i] >= old_cursor.col) { + cur_col = curmatch.cols.items[i]; + curwin->w_cursor.lnum = curmatch.lnum; + curwin->w_cursor.col = cur_col; break; } } - // match on cursor's line, after the cursor - if (cur_col != -1) { - curwin->w_cursor.lnum = cur_lnum; - curwin->w_cursor.col = cur_col; - break; - } - // 2. Match on line after cursor, just put cursor on column - // of first match there - } else if (cur_lnum > old_cursor.lnum) { - cur_col = current.cols.items[0]; - curwin->w_cursor.lnum = cur_lnum; - curwin->w_cursor.col = cur_col; - break; + } else if (curmatch.lnum > old_cursor.lnum) { + // After cursor; put cursor on first match there. + cur_col = curmatch.cols.items[0]; + curwin->w_cursor.lnum = curmatch.lnum; + curwin->w_cursor.col = cur_col; } } @@ -3992,16 +3978,13 @@ skip: curwin->w_cursor = old_cursor; // don't move the cursor } - MatchedLine current; - for (size_t j = 0; j < matched_lines.size; j++) { - current = matched_lines.items[j]; - if (current.line) { - xfree(current.line); - } - kv_destroy(current.cols); + for (MatchedLine m; kv_size(matched_lines);) { + m = kv_pop(matched_lines); + xfree(m.line); + kv_destroy(m.cols); } - kv_destroy(matched_lines); + return incsub_buf; } // NOLINT(readability/fn_size) @@ -6069,13 +6052,15 @@ static buf_T *incsub_display(char_u *pat, char_u *sub, buf_open_special(incsub_buf ? bufnr : 0, "[inc_sub]", "incsub"); buf_clear(); incsub_buf = curbuf; - set_option_value((char_u *)"bl", 0L, NULL, OPT_LOCAL); set_option_value((char_u *)"bh", 0L, (char_u *)"hide", OPT_LOCAL); bufnr = incsub_buf->handle; + curbuf->b_p_bl = false; curbuf->b_p_ma = true; curbuf->b_p_ul = -1; - curwin->w_p_fen = false; curbuf->b_p_tw = 0; // Reset 'textwidth' (was set by ftplugin) + curwin->w_p_cul = false; + curwin->w_p_spell = false; + curwin->w_p_fen = false; // Width of the "| lnum|..." column which displays the line numbers. linenr_T highest_num_line = kv_last(*matched_lines).lnum; diff --git a/test/functional/ui/incsubstitute_spec.lua b/test/functional/ui/incsubstitute_spec.lua index 88c02c7375..e52e12a8ce 100644 --- a/test/functional/ui/incsubstitute_spec.lua +++ b/test/functional/ui/incsubstitute_spec.lua @@ -12,6 +12,7 @@ local meths = helpers.meths local neq = helpers.neq local ok = helpers.ok local source = helpers.source +local wait = helpers.wait local default_text = [[ Inc substitution on @@ -40,6 +41,7 @@ local function common_setup(screen, incsub, text) [13] = {bold = true, foreground = Screen.colors.SeaGreen}, [14] = {foreground = Screen.colors.White, background = Screen.colors.Red}, [15] = {bold=true, foreground=Screen.colors.Blue}, + [16] = {background=Screen.colors.Grey90}, -- cursorline }) end @@ -120,7 +122,7 @@ describe("'incsubstitute' preserves", function() some text 1 some text 2]]) feed(":%s/e/XXX/") - helpers.wait() + wait() eq(expected_tick, eval("b:changedtick")) end @@ -703,12 +705,13 @@ describe("incsubstitute=split", function() ]]) end) - it('highlights the pattern with :set hlsearch', function() + it("'hlsearch' highlights the substitution, 'cursorline' does not", function() execute("set hlsearch") + execute("set cursorline") -- Should NOT appear in the preview window. feed(":%s/tw") screen:expect([[ Inc substitution on | - {9:tw}o lines | + {9:tw}{16:o lines }| | {15:~ }| {15:~ }| @@ -796,8 +799,21 @@ describe("incsubstitute=split", function() ]]) end) - it('does not increase the buffer numbers unduly', function() - feed(":%s/tw/Xo/g<enter>") + it('does not spam the buffer numbers', function() + -- The preview buffer is re-used (unless user deleted it), so buffer numbers + -- will not increase on each keystroke. + feed(":%s/tw/Xo/g") + -- Delete and re-type the g a few times. + feed("<BS>") + wait() + feed("g") + wait() + feed("<BS>") + wait() + feed("g") + wait() + feed("<CR>") + wait() feed(":vs tmp<enter>") eq(3, helpers.call('bufnr', '$')) end) @@ -963,7 +979,7 @@ describe("'incsubstitute' and :cnoremap", function() end end) - it('work then mappings move the cursor', function() + it('work when mappings move the cursor', function() for _, case in pairs(cases) do refresh(case) execute("cnoremap ,S LINES/<left><left><left><left><left><left>") |