'inccommand': disable 'cursorline', 'spell' in preview

This commit is contained in:
Justin M. Keyes
2016-11-06 23:58:53 +01:00
parent e31f9007e4
commit d0689eb0b2
3 changed files with 49 additions and 49 deletions

View File

@@ -134,7 +134,6 @@ Events:
|TextYankPost| |TextYankPost|
Highlight groups: Highlight groups:
|hl-Substitute|
|hl-QuickFixLine| |hl-QuickFixLine|
|hl-Substitute| |hl-Substitute|
|hl-TermCursor| |hl-TermCursor|

View File

@@ -3946,42 +3946,28 @@ skip:
// Show 'incsubstitute' preview if there are matched lines. // Show 'incsubstitute' preview if there are matched lines.
buf_T *incsub_buf = NULL; buf_T *incsub_buf = NULL;
if (matched_lines.size != 0 && pat != NULL && *p_ics != NUL && eap->is_live) { if (eap->is_live && matched_lines.size != 0 && pat != NULL && *p_ics != NUL) {
// Place cursor on the first match after the cursor. // Place cursor on the first match after the cursor. (If all matches are
// If all matches are before the cursor, then do_sub already placed the // above, then do_sub already placed cursor on the last match.)
// cursor on the last match.
linenr_T cur_lnum = 0;
colnr_T cur_col = -1; colnr_T cur_col = -1;
MatchedLine current; MatchedLine curmatch;
for (size_t j = 0; j < matched_lines.size && cur_col == -1; j++) {
for (size_t j = 0; j < matched_lines.size; j++) { curmatch = matched_lines.items[j];
current = matched_lines.items[j]; if (curmatch.lnum == old_cursor.lnum) {
cur_lnum = current.lnum; // On cursor line; iterate in-line matches to find one after cursor.
for (size_t i = 0; i < curmatch.cols.size; i++) {
// 1. Match on line of the cursor, need to iterate over the if (curmatch.cols.items[i] >= old_cursor.col) {
// matches on this line to see if there is one on a later cur_col = curmatch.cols.items[i];
// column curwin->w_cursor.lnum = curmatch.lnum;
if (cur_lnum == old_cursor.lnum) { curwin->w_cursor.col = cur_col;
for (size_t i = 0; i < current.cols.size; i++) {
if (current.cols.items[i] >= old_cursor.col) {
cur_col = current.cols.items[i];
break; break;
} }
} }
// match on cursor's line, after the cursor } else if (curmatch.lnum > old_cursor.lnum) {
if (cur_col != -1) { // After cursor; put cursor on first match there.
curwin->w_cursor.lnum = cur_lnum; cur_col = curmatch.cols.items[0];
curwin->w_cursor.col = cur_col; curwin->w_cursor.lnum = curmatch.lnum;
break; curwin->w_cursor.col = cur_col;
}
// 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;
} }
} }
@@ -3992,16 +3978,13 @@ skip:
curwin->w_cursor = old_cursor; // don't move the cursor curwin->w_cursor = old_cursor; // don't move the cursor
} }
MatchedLine current; for (MatchedLine m; kv_size(matched_lines);) {
for (size_t j = 0; j < matched_lines.size; j++) { m = kv_pop(matched_lines);
current = matched_lines.items[j]; xfree(m.line);
if (current.line) { kv_destroy(m.cols);
xfree(current.line);
}
kv_destroy(current.cols);
} }
kv_destroy(matched_lines); kv_destroy(matched_lines);
return incsub_buf; return incsub_buf;
} // NOLINT(readability/fn_size) } // 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_open_special(incsub_buf ? bufnr : 0, "[inc_sub]", "incsub");
buf_clear(); buf_clear();
incsub_buf = curbuf; 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); set_option_value((char_u *)"bh", 0L, (char_u *)"hide", OPT_LOCAL);
bufnr = incsub_buf->handle; bufnr = incsub_buf->handle;
curbuf->b_p_bl = false;
curbuf->b_p_ma = true; curbuf->b_p_ma = true;
curbuf->b_p_ul = -1; curbuf->b_p_ul = -1;
curwin->w_p_fen = false;
curbuf->b_p_tw = 0; // Reset 'textwidth' (was set by ftplugin) 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. // Width of the "| lnum|..." column which displays the line numbers.
linenr_T highest_num_line = kv_last(*matched_lines).lnum; linenr_T highest_num_line = kv_last(*matched_lines).lnum;

View File

@@ -12,6 +12,7 @@ local meths = helpers.meths
local neq = helpers.neq local neq = helpers.neq
local ok = helpers.ok local ok = helpers.ok
local source = helpers.source local source = helpers.source
local wait = helpers.wait
local default_text = [[ local default_text = [[
Inc substitution on Inc substitution on
@@ -40,6 +41,7 @@ local function common_setup(screen, incsub, text)
[13] = {bold = true, foreground = Screen.colors.SeaGreen}, [13] = {bold = true, foreground = Screen.colors.SeaGreen},
[14] = {foreground = Screen.colors.White, background = Screen.colors.Red}, [14] = {foreground = Screen.colors.White, background = Screen.colors.Red},
[15] = {bold=true, foreground=Screen.colors.Blue}, [15] = {bold=true, foreground=Screen.colors.Blue},
[16] = {background=Screen.colors.Grey90}, -- cursorline
}) })
end end
@@ -120,7 +122,7 @@ describe("'incsubstitute' preserves", function()
some text 1 some text 1
some text 2]]) some text 2]])
feed(":%s/e/XXX/") feed(":%s/e/XXX/")
helpers.wait() wait()
eq(expected_tick, eval("b:changedtick")) eq(expected_tick, eval("b:changedtick"))
end end
@@ -703,12 +705,13 @@ describe("incsubstitute=split", function()
]]) ]])
end) end)
it('highlights the pattern with :set hlsearch', function() it("'hlsearch' highlights the substitution, 'cursorline' does not", function()
execute("set hlsearch") execute("set hlsearch")
execute("set cursorline") -- Should NOT appear in the preview window.
feed(":%s/tw") feed(":%s/tw")
screen:expect([[ screen:expect([[
Inc substitution on | Inc substitution on |
{9:tw}o lines | {9:tw}{16:o lines }|
| |
{15:~ }| {15:~ }|
{15:~ }| {15:~ }|
@@ -796,8 +799,21 @@ describe("incsubstitute=split", function()
]]) ]])
end) end)
it('does not increase the buffer numbers unduly', function() it('does not spam the buffer numbers', function()
feed(":%s/tw/Xo/g<enter>") -- 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>") feed(":vs tmp<enter>")
eq(3, helpers.call('bufnr', '$')) eq(3, helpers.call('bufnr', '$'))
end) end)
@@ -963,7 +979,7 @@ describe("'incsubstitute' and :cnoremap", function()
end end
end) end)
it('work then mappings move the cursor', function() it('work when mappings move the cursor', function()
for _, case in pairs(cases) do for _, case in pairs(cases) do
refresh(case) refresh(case)
execute("cnoremap ,S LINES/<left><left><left><left><left><left>") execute("cnoremap ,S LINES/<left><left><left><left><left><left>")