patch 9.0.0697: cursor in wrong position with Visual substitute
Problem: Cursor in wrong position with Visual substitute.
Solution: When restoring 'linebreak' mark the virtual column as invalid.
(closes #11309, closes #11311)
diff --git a/src/testdir/dumps/Test_linebreak_reset_restore_1.dump b/src/testdir/dumps/Test_linebreak_reset_restore_1.dump
new file mode 100644
index 0000000..4a63630
--- /dev/null
+++ b/src/testdir/dumps/Test_linebreak_reset_restore_1.dump
@@ -0,0 +1,8 @@
+|a+0&#ffffff0@64| @9
+|b@9| > @63
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+| +0#0000000&@56|1|,|7|8|-|8|7| @6|A|l@1|
diff --git a/src/testdir/test_listlbr.vim b/src/testdir/test_listlbr.vim
index 97d6ccd..ace398b 100644
--- a/src/testdir/test_listlbr.vim
+++ b/src/testdir/test_listlbr.vim
@@ -8,6 +8,7 @@
CheckFeature conceal
source view_util.vim
+source screendump.vim
function s:screen_lines(lnum, width) abort
return ScreenLines(a:lnum, a:width)
@@ -133,6 +134,26 @@
call s:close_windows()
endfunc
+func Test_linebreak_reset_restore()
+ CheckScreendump
+
+ let lines =<< trim END
+ vim9script
+ &linebreak = true
+ &showcmd = true
+ &showmode = false
+ ('a'->repeat(&columns - 10) .. ' ' .. 'b'->repeat(10) .. ' c')->setline(1)
+ END
+ call writefile(lines, 'XlbrResetRestore', 'D')
+ let buf = RunVimInTerminal('-S XlbrResetRestore', {'rows': 8})
+
+ call term_sendkeys(buf, '$v$s')
+ call VerifyScreenDump(buf, 'Test_linebreak_reset_restore_1', {})
+
+ call term_sendkeys(buf, "\<Esc>")
+ call StopVimInTerminal(buf)
+endfunc
+
func Test_virtual_block()
call s:test_windows('setl sbr=+')
call setline(1, [
diff --git a/src/testdir/test_visual.vim b/src/testdir/test_visual.vim
index 31ce829..71156f8 100644
--- a/src/testdir/test_visual.vim
+++ b/src/testdir/test_visual.vim
@@ -1501,5 +1501,37 @@
exe 'bwipe!' buf2
endfunc
+" Test that cursor is drawn at correct position after an operator in Visual
+" mode when 'linebreak' and 'showcmd' are enabled.
+func Test_visual_operator_with_linebreak()
+ CheckRunVimInTerminal
+
+ let lines =<< trim END
+ set linebreak showcmd noshowmode
+ call setline(1, repeat('a', &columns - 10) .. ' bbbbbbbbbb c')
+ END
+ call writefile(lines, 'XTest_visual_op_linebreak', 'D')
+
+ let buf = RunVimInTerminal('-S XTest_visual_op_linebreak', {'rows': 6})
+
+ 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, "$\<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])})
+
+ " clean up
+ call term_sendkeys(buf, "\<Esc>")
+ call StopVimInTerminal(buf)
+endfunc
" vim: shiftwidth=2 sts=2 expandtab