mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
Merge pull request #20554 from zeertzjq/vim-9.0.0697
vim-patch:9.0.{0697,0702}: cursor in wrong position with 'linebreak'
This commit is contained in:
@@ -4172,6 +4172,29 @@ theend:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Reset 'linebreak' and take care of side effects.
|
||||||
|
/// @return the previous value, to be passed to restore_lbr().
|
||||||
|
static bool reset_lbr(void)
|
||||||
|
{
|
||||||
|
if (!curwin->w_p_lbr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// changing 'linebreak' may require w_virtcol to be updated
|
||||||
|
curwin->w_p_lbr = false;
|
||||||
|
curwin->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Restore 'linebreak' and take care of side effects.
|
||||||
|
static void restore_lbr(bool lbr_saved)
|
||||||
|
{
|
||||||
|
if (!curwin->w_p_lbr && lbr_saved) {
|
||||||
|
// changing 'linebreak' may require w_virtcol to be updated
|
||||||
|
curwin->w_p_lbr = true;
|
||||||
|
curwin->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// prepare a few things for block mode yank/delete/tilde
|
/// prepare a few things for block mode yank/delete/tilde
|
||||||
///
|
///
|
||||||
/// for delete:
|
/// for delete:
|
||||||
@@ -4191,10 +4214,9 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool
|
|||||||
char *line;
|
char *line;
|
||||||
char *prev_pstart;
|
char *prev_pstart;
|
||||||
char *prev_pend;
|
char *prev_pend;
|
||||||
const int lbr_saved = curwin->w_p_lbr;
|
|
||||||
|
|
||||||
// Avoid a problem with unwanted linebreaks in block mode.
|
// Avoid a problem with unwanted linebreaks in block mode.
|
||||||
curwin->w_p_lbr = false;
|
const bool lbr_saved = reset_lbr();
|
||||||
|
|
||||||
bdp->startspaces = 0;
|
bdp->startspaces = 0;
|
||||||
bdp->endspaces = 0;
|
bdp->endspaces = 0;
|
||||||
bdp->textlen = 0;
|
bdp->textlen = 0;
|
||||||
@@ -4308,7 +4330,7 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool
|
|||||||
}
|
}
|
||||||
bdp->textcol = (colnr_T)(pstart - line);
|
bdp->textcol = (colnr_T)(pstart - line);
|
||||||
bdp->textstart = (char_u *)pstart;
|
bdp->textstart = (char_u *)pstart;
|
||||||
curwin->w_p_lbr = lbr_saved;
|
restore_lbr(lbr_saved);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handle the add/subtract operator.
|
/// Handle the add/subtract operator.
|
||||||
@@ -5733,10 +5755,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
|||||||
const bool redo_yank = vim_strchr(p_cpo, CPO_YANK) != NULL && !gui_yank;
|
const bool redo_yank = vim_strchr(p_cpo, CPO_YANK) != NULL && !gui_yank;
|
||||||
|
|
||||||
// Avoid a problem with unwanted linebreaks in block mode
|
// Avoid a problem with unwanted linebreaks in block mode
|
||||||
if (curwin->w_p_lbr) {
|
(void)reset_lbr();
|
||||||
curwin->w_valid &= ~VALID_VIRTCOL;
|
|
||||||
}
|
|
||||||
curwin->w_p_lbr = false;
|
|
||||||
oap->is_VIsual = VIsual_active;
|
oap->is_VIsual = VIsual_active;
|
||||||
if (oap->motion_force == 'V') {
|
if (oap->motion_force == 'V') {
|
||||||
oap->motion_type = kMTLineWise;
|
oap->motion_type = kMTLineWise;
|
||||||
@@ -6025,7 +6044,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
|||||||
|| oap->op_type == OP_FILTER)
|
|| oap->op_type == OP_FILTER)
|
||||||
&& oap->motion_force == NUL) {
|
&& oap->motion_force == NUL) {
|
||||||
// Make sure redrawing is correct.
|
// Make sure redrawing is correct.
|
||||||
curwin->w_p_lbr = lbr_saved;
|
restore_lbr(lbr_saved);
|
||||||
redraw_curbuf_later(UPD_INVERTED);
|
redraw_curbuf_later(UPD_INVERTED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6057,7 +6076,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
|||||||
// 'modifiable is off or creating a fold.
|
// 'modifiable is off or creating a fold.
|
||||||
if (oap->is_VIsual && (oap->empty || !MODIFIABLE(curbuf)
|
if (oap->is_VIsual && (oap->empty || !MODIFIABLE(curbuf)
|
||||||
|| oap->op_type == OP_FOLD)) {
|
|| oap->op_type == OP_FOLD)) {
|
||||||
curwin->w_p_lbr = lbr_saved;
|
restore_lbr(lbr_saved);
|
||||||
redraw_curbuf_later(UPD_INVERTED);
|
redraw_curbuf_later(UPD_INVERTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6133,7 +6152,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
|||||||
CancelRedo();
|
CancelRedo();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
curwin->w_p_lbr = lbr_saved;
|
restore_lbr(lbr_saved);
|
||||||
oap->excl_tr_ws = cap->cmdchar == 'z';
|
oap->excl_tr_ws = cap->cmdchar == 'z';
|
||||||
(void)op_yank(oap, !gui_yank);
|
(void)op_yank(oap, !gui_yank);
|
||||||
}
|
}
|
||||||
@@ -6157,7 +6176,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
|||||||
restart_edit = 0;
|
restart_edit = 0;
|
||||||
|
|
||||||
// Restore linebreak, so that when the user edits it looks as before.
|
// Restore linebreak, so that when the user edits it looks as before.
|
||||||
curwin->w_p_lbr = lbr_saved;
|
restore_lbr(lbr_saved);
|
||||||
|
|
||||||
// Reset finish_op now, don't want it set inside edit().
|
// Reset finish_op now, don't want it set inside edit().
|
||||||
finish_op = false;
|
finish_op = false;
|
||||||
@@ -6228,9 +6247,8 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
|||||||
case OP_FUNCTION: {
|
case OP_FUNCTION: {
|
||||||
redo_VIsual_T save_redo_VIsual = redo_VIsual;
|
redo_VIsual_T save_redo_VIsual = redo_VIsual;
|
||||||
|
|
||||||
// Restore linebreak, so that when the user edits it looks as
|
// Restore linebreak, so that when the user edits it looks as before.
|
||||||
// before.
|
restore_lbr(lbr_saved);
|
||||||
curwin->w_p_lbr = lbr_saved;
|
|
||||||
// call 'operatorfunc'
|
// call 'operatorfunc'
|
||||||
op_function(oap);
|
op_function(oap);
|
||||||
|
|
||||||
@@ -6254,12 +6272,12 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
|||||||
restart_edit = 0;
|
restart_edit = 0;
|
||||||
|
|
||||||
// Restore linebreak, so that when the user edits it looks as before.
|
// Restore linebreak, so that when the user edits it looks as before.
|
||||||
curwin->w_p_lbr = lbr_saved;
|
restore_lbr(lbr_saved);
|
||||||
|
|
||||||
op_insert(oap, cap->count1);
|
op_insert(oap, cap->count1);
|
||||||
|
|
||||||
// Reset linebreak, so that formatting works correctly.
|
// Reset linebreak, so that formatting works correctly.
|
||||||
curwin->w_p_lbr = false;
|
(void)reset_lbr();
|
||||||
|
|
||||||
// TODO(brammool): when inserting in several lines, should format all
|
// TODO(brammool): when inserting in several lines, should format all
|
||||||
// the lines.
|
// the lines.
|
||||||
@@ -6280,7 +6298,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
|||||||
CancelRedo();
|
CancelRedo();
|
||||||
} else {
|
} else {
|
||||||
// Restore linebreak, so that when the user edits it looks as before.
|
// Restore linebreak, so that when the user edits it looks as before.
|
||||||
curwin->w_p_lbr = lbr_saved;
|
restore_lbr(lbr_saved);
|
||||||
|
|
||||||
op_replace(oap, cap->nchar);
|
op_replace(oap, cap->nchar);
|
||||||
}
|
}
|
||||||
@@ -6318,7 +6336,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
|||||||
CancelRedo();
|
CancelRedo();
|
||||||
} else {
|
} else {
|
||||||
VIsual_active = true;
|
VIsual_active = true;
|
||||||
curwin->w_p_lbr = lbr_saved;
|
restore_lbr(lbr_saved);
|
||||||
op_addsub(oap, (linenr_T)cap->count1, redo_VIsual.rv_arg);
|
op_addsub(oap, (linenr_T)cap->count1, redo_VIsual.rv_arg);
|
||||||
VIsual_active = false;
|
VIsual_active = false;
|
||||||
}
|
}
|
||||||
@@ -6333,7 +6351,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
|||||||
if (!p_sol && oap->motion_type == kMTLineWise && !oap->end_adjusted
|
if (!p_sol && oap->motion_type == kMTLineWise && !oap->end_adjusted
|
||||||
&& (oap->op_type == OP_LSHIFT || oap->op_type == OP_RSHIFT
|
&& (oap->op_type == OP_LSHIFT || oap->op_type == OP_RSHIFT
|
||||||
|| oap->op_type == OP_DELETE)) {
|
|| oap->op_type == OP_DELETE)) {
|
||||||
curwin->w_p_lbr = false;
|
(void)reset_lbr();
|
||||||
coladvance(curwin->w_curswant = old_col);
|
coladvance(curwin->w_curswant = old_col);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -6342,7 +6360,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
|||||||
clearop(oap);
|
clearop(oap);
|
||||||
motion_force = NUL;
|
motion_force = NUL;
|
||||||
}
|
}
|
||||||
curwin->w_p_lbr = lbr_saved;
|
restore_lbr(lbr_saved);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if the default register (used in an unnamed paste) should be a
|
/// Check if the default register (used in an unnamed paste) should be a
|
||||||
|
@@ -7,6 +7,7 @@ CheckOption linebreak
|
|||||||
CheckFeature conceal
|
CheckFeature conceal
|
||||||
|
|
||||||
source view_util.vim
|
source view_util.vim
|
||||||
|
source screendump.vim
|
||||||
|
|
||||||
function s:screen_lines(lnum, width) abort
|
function s:screen_lines(lnum, width) abort
|
||||||
return ScreenLines(a:lnum, a:width)
|
return ScreenLines(a:lnum, a:width)
|
||||||
@@ -133,6 +134,45 @@ func Test_linebreak_with_visual_operations()
|
|||||||
call s:close_windows()
|
call s:close_windows()
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" Test that cursor is drawn at correct position after an operator when
|
||||||
|
" 'linebreak' is enabled.
|
||||||
|
func Test_linebreak_reset_restore()
|
||||||
|
CheckScreendump
|
||||||
|
|
||||||
|
" f_wincol() calls validate_cursor()
|
||||||
|
let lines =<< trim END
|
||||||
|
set linebreak showcmd noshowmode formatexpr=wincol()-wincol()
|
||||||
|
call setline(1, repeat('a', &columns - 10) .. ' bbbbbbbbbb c')
|
||||||
|
END
|
||||||
|
call writefile(lines, 'XlbrResetRestore', 'D')
|
||||||
|
let buf = RunVimInTerminal('-S XlbrResetRestore', {'rows': 8})
|
||||||
|
|
||||||
|
call term_sendkeys(buf, '$v$')
|
||||||
|
call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])})
|
||||||
|
call term_sendkeys(buf, 'zo')
|
||||||
|
call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])})
|
||||||
|
|
||||||
|
call term_sendkeys(buf, '$v$')
|
||||||
|
call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])})
|
||||||
|
call term_sendkeys(buf, 'gq')
|
||||||
|
call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])})
|
||||||
|
|
||||||
|
call term_sendkeys(buf, "$\<C-V>$")
|
||||||
|
call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])})
|
||||||
|
call term_sendkeys(buf, 'I')
|
||||||
|
call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])})
|
||||||
|
|
||||||
|
call term_sendkeys(buf, "\<Esc>$v$")
|
||||||
|
call WaitForAssert({-> assert_equal(13, term_getcursor(buf)[1])})
|
||||||
|
call term_sendkeys(buf, 's')
|
||||||
|
call WaitForAssert({-> assert_equal(12, term_getcursor(buf)[1])})
|
||||||
|
call VerifyScreenDump(buf, 'Test_linebreak_reset_restore_1', {})
|
||||||
|
|
||||||
|
" clean up
|
||||||
|
call term_sendkeys(buf, "\<Esc>")
|
||||||
|
call StopVimInTerminal(buf)
|
||||||
|
endfunc
|
||||||
|
|
||||||
func Test_virtual_block()
|
func Test_virtual_block()
|
||||||
call s:test_windows('setl sbr=+')
|
call s:test_windows('setl sbr=+')
|
||||||
call setline(1, [
|
call setline(1, [
|
||||||
|
@@ -1492,5 +1492,4 @@ func Test_switch_buffer_ends_visual_mode()
|
|||||||
exe 'bwipe!' buf2
|
exe 'bwipe!' buf2
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
@@ -1,11 +1,12 @@
|
|||||||
-- Test for linebreak and list option (non-utf8)
|
-- Test for linebreak and list option (non-utf8)
|
||||||
|
|
||||||
local helpers = require('test.functional.helpers')(after_each)
|
local helpers = require('test.functional.helpers')(after_each)
|
||||||
|
local Screen = require('test.functional.ui.screen')
|
||||||
local feed, insert, source = helpers.feed, helpers.insert, helpers.source
|
local feed, insert, source = helpers.feed, helpers.insert, helpers.source
|
||||||
local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect
|
local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect
|
||||||
|
|
||||||
describe('listlbr', function()
|
describe('listlbr', function()
|
||||||
setup(clear)
|
before_each(clear)
|
||||||
|
|
||||||
-- luacheck: ignore 621 (Indentation)
|
-- luacheck: ignore 621 (Indentation)
|
||||||
-- luacheck: ignore 611 (Line contains only whitespaces)
|
-- luacheck: ignore 611 (Line contains only whitespaces)
|
||||||
@@ -195,4 +196,97 @@ describe('listlbr', function()
|
|||||||
aa>-----a-$
|
aa>-----a-$
|
||||||
~ ]])
|
~ ]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- oldtest: Test_linebreak_reset_restore()
|
||||||
|
it('cursor position is drawn correctly after operator', function()
|
||||||
|
local screen = Screen.new(60, 6)
|
||||||
|
screen:set_default_attr_ids({
|
||||||
|
[0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
|
||||||
|
[1] = {background = Screen.colors.LightGrey}, -- Visual
|
||||||
|
[2] = {background = Screen.colors.Red, foreground = Screen.colors.White}, -- ErrorMsg
|
||||||
|
})
|
||||||
|
screen:attach()
|
||||||
|
|
||||||
|
-- f_wincol() calls validate_cursor()
|
||||||
|
source([[
|
||||||
|
set linebreak showcmd noshowmode formatexpr=wincol()-wincol()
|
||||||
|
call setline(1, repeat('a', &columns - 10) .. ' bbbbbbbbbb c')
|
||||||
|
]])
|
||||||
|
|
||||||
|
feed('$v$')
|
||||||
|
screen:expect([[
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
|
||||||
|
bbbbbbbbbb {1:c}^ |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
2 |
|
||||||
|
]])
|
||||||
|
feed('zo')
|
||||||
|
screen:expect([[
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
|
||||||
|
bbbbbbbbbb ^c |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{2:E490: No fold found} |
|
||||||
|
]])
|
||||||
|
|
||||||
|
feed('$v$')
|
||||||
|
screen:expect([[
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
|
||||||
|
bbbbbbbbbb {1:c}^ |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{2:E490: No fold found} 2 |
|
||||||
|
]])
|
||||||
|
feed('gq')
|
||||||
|
screen:expect([[
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
|
||||||
|
bbbbbbbbbb ^c |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{2:E490: No fold found} |
|
||||||
|
]])
|
||||||
|
|
||||||
|
feed('$<C-V>$')
|
||||||
|
screen:expect([[
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
|
||||||
|
bbbbbbbbbb {1:c}^ |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{2:E490: No fold found} 1x2 |
|
||||||
|
]])
|
||||||
|
feed('I')
|
||||||
|
screen:expect([[
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
|
||||||
|
bbbbbbbbbb ^c |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{2:E490: No fold found} |
|
||||||
|
]])
|
||||||
|
|
||||||
|
feed('<Esc>$v$')
|
||||||
|
screen:expect([[
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
|
||||||
|
bbbbbbbbbb {1:c}^ |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{2:E490: No fold found} 2 |
|
||||||
|
]])
|
||||||
|
feed('s')
|
||||||
|
screen:expect([[
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
|
||||||
|
bbbbbbbbbb ^ |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{2:E490: No fold found} |
|
||||||
|
]])
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user