vim-patch:8.2.4660: cursorcolumn is sometimes not correct

Problem:    Cursorcolumn is sometimes not correct.
Solution:   Recompute the cursor column when entering Insert mode and the
            cursor is on a character wider than a screen cell.
782c6744b4
This commit is contained in:
zeertzjq
2022-04-01 19:46:17 +08:00
parent 377e875211
commit 139828cc7e
3 changed files with 66 additions and 6 deletions

View File

@@ -390,9 +390,13 @@ static void insert_enter(InsertState *s)
trigger_modechanged();
stop_insert_mode = false;
// Need to recompute the cursor position, it might move when the cursor is
// on a TAB or special character.
curs_columns(curwin, true);
// Need to recompute the cursor position, it might move when the cursor
// is on a TAB or special character.
// ptr2cells() treats a TAB character as double-width.
if (ptr2cells(get_cursor_pos_ptr()) > 1) {
curwin->w_valid &= ~VALID_VIRTCOL;
curs_columns(curwin, true);
}
// Enable langmap or IME, indicated by 'iminsert'.
// Note that IME may enabled/disabled without us noticing here, thus the

View File

@@ -597,6 +597,28 @@ func Test_cursorline_with_visualmode()
call delete('Xtest_cursorline_with_visualmode')
endfunc
func Test_cursorcolumn_insert_on_tab()
CheckScreendump
let lines =<< trim END
call setline(1, ['123456789', "a\tb"])
set cursorcolumn
call cursor(2, 2)
END
call writefile(lines, 'Xcuc_insert_on_tab')
let buf = RunVimInTerminal('-S Xcuc_insert_on_tab', #{rows: 8})
call TermWait(buf)
call VerifyScreenDump(buf, 'Test_cursorcolumn_insert_on_tab_1', {})
call term_sendkeys(buf, 'i')
call TermWait(buf)
call VerifyScreenDump(buf, 'Test_cursorcolumn_insert_on_tab_2', {})
call StopVimInTerminal(buf)
call delete('Xcuc_insert_on_tab')
endfunc
func Test_cursorcolumn_callback()
CheckScreendump
CheckFeature timers