vim-patch:8.2.3122: with 'nowrap' cursor position is unexected in narrow window (#17935)

Problem:    With 'nowrap' cursor position is unexected in narrow window.
            (Leonid V.  Fedorenchik)
Solution:   Put cursor on the last non-empty line. (closes vim/vim#8525)
30441bb3d5
This commit is contained in:
zeertzjq
2022-04-01 07:11:38 +08:00
committed by GitHub
parent dc48330b9d
commit 8a6cf51a71
3 changed files with 103 additions and 46 deletions

View File

@@ -778,8 +778,13 @@ void curs_columns(win_T *wp, int may_scroll)
int textwidth = wp->w_width_inner - extra;
if (textwidth <= 0) {
// No room for text, put cursor in last char of window.
// If not wrapping, the last non-empty line.
wp->w_wcol = wp->w_width_inner - 1;
if (wp->w_p_wrap) {
wp->w_wrow = wp->w_height_inner - 1;
} else {
wp->w_wrow = wp->w_height_inner - 1 - wp->w_empty_rows;
}
} else if (wp->w_p_wrap
&& wp->w_width_inner != 0) {
width = textwidth + win_col_off2(wp);

View File

@@ -542,6 +542,12 @@ func Test_listchars_foldcolumn()
call VerifyScreenDump(buf, 'Test_listchars_04', {})
call term_sendkeys(buf, "\<C-W>>")
call VerifyScreenDump(buf, 'Test_listchars_05', {})
call term_sendkeys(buf, "\<C-W>h")
call term_sendkeys(buf, ":set nowrap foldcolumn=4\<CR>")
call term_sendkeys(buf, "15\<C-W><")
call VerifyScreenDump(buf, 'Test_listchars_06', {})
call term_sendkeys(buf, "4\<C-W><")
call VerifyScreenDump(buf, 'Test_listchars_07', {})
" clean up
call StopVimInTerminal(buf)

View File

@@ -102,6 +102,12 @@ describe("'listchars'", function()
it('"exceeds" character does not appear in foldcolumn vim-patch:8.2.3121', function()
local screen = Screen.new(60, 10)
screen:set_default_attr_ids({
[1] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
[2] = {bold = true, reverse = true}, -- StatusLine
[3] = {reverse = true}, -- StatusLineNC, VertSplit
[4] = {background = Screen.colors.Grey, foreground = Screen.colors.DarkBlue}, -- FoldColumn, SignColumn
})
screen:attach()
exec([[
call setline(1, ['aaa', '', 'a', 'aaaaaa'])
@@ -111,68 +117,108 @@ describe("'listchars'", function()
]])
feed('13<C-W>>')
screen:expect([[
aaa │ a>│ ^aaa |
|
a a a |
aaaaaa │ a>│ aaaaaa |
~ │~ │~ |
~ │~ │~ |
~ │~ │~ |
~ │~ │~ |
[No Name] [+] <[+] [No Name] [+] |
{4: }aaa {3:│}{4: }a{1:>}{3:│}{4: }^aaa |
{4: } {3:│}{4: } {3:│}{4: } |
{4: }a {3:│}{4: }a {3:│}{4: }a |
{4: }aaaaaa {3:│}{4: }a{1:>}{3:│}{4: }aaaaaa |
{1:~ }{3:│}{1:~ }{3:│}{1:~ }|
{1:~ }{3:│}{1:~ }{3:│}{1:~ }|
{1:~ }{3:│}{1:~ }{3:│}{1:~ }|
{1:~ }{3:│}{1:~ }{3:│}{1:~ }|
{3:[No Name] [+] <[+] }{2:[No Name] [+] }|
|
]])
feed('<C-W>>')
screen:expect([[
aaa │ >│ ^aaa |
│ │ |
a │ a│ a |
aaaaaa │ >│ aaaaaa |
~ │~ │~ |
~ │~ │~ |
~ │~ │~ |
~ │~ │~ |
[No Name] [+] <+] [No Name] [+] |
{4: }aaa {3:│}{4: }{1:>}{3:│}{4: }^aaa |
{4: } {3:│}{4: } {3:│}{4: } |
{4: }a {3:│}{4: }a{3:│}{4: }a |
{4: }aaaaaa {3:│}{4: }{1:>}{3:│}{4: }aaaaaa |
{1:~ }{3:│}{1:~ }{3:│}{1:~ }|
{1:~ }{3:│}{1:~ }{3:│}{1:~ }|
{1:~ }{3:│}{1:~ }{3:│}{1:~ }|
{1:~ }{3:│}{1:~ }{3:│}{1:~ }|
{3:[No Name] [+] <+] }{2:[No Name] [+] }|
|
]])
feed('<C-W>>')
screen:expect([[
aaa │ │ ^aaa |
│ │ |
a │ │ a |
aaaaaa │ │ aaaaaa |
~ │~ │~ |
~ │~ │~ |
~ │~ │~ |
~ │~ │~ |
[No Name] [+] <] [No Name] [+] |
{4: }aaa {3:│}{4: }{3:│}{4: }^aaa |
{4: } {3:│}{4: }{3:│}{4: } |
{4: }a {3:│}{4: }{3:│}{4: }a |
{4: }aaaaaa {3:│}{4: }{3:│}{4: }aaaaaa |
{1:~ }{3:│}{1:~ }{3:│}{1:~ }|
{1:~ }{3:│}{1:~ }{3:│}{1:~ }|
{1:~ }{3:│}{1:~ }{3:│}{1:~ }|
{1:~ }{3:│}{1:~ }{3:│}{1:~ }|
{3:[No Name] [+] <] }{2:[No Name] [+] }|
|
]])
feed('<C-W>>')
screen:expect([[
aaa │ │ ^aaa |
│ │ |
a │ │ a |
aaaaaa │ │ aaaaaa |
~ │~ │~ |
~ │~ │~ |
~ │~ │~ |
~ │~ │~ |
[No Name] [+] < [No Name] [+] |
{4: }aaa {3:│}{4: }{3:│}{4: }^aaa |
{4: } {3:│}{4: }{3:│}{4: } |
{4: }a {3:│}{4: }{3:│}{4: }a |
{4: }aaaaaa {3:│}{4: }{3:│}{4: }aaaaaa |
{1:~ }{3:│}{1:~ }{3:│}{1:~ }|
{1:~ }{3:│}{1:~ }{3:│}{1:~ }|
{1:~ }{3:│}{1:~ }{3:│}{1:~ }|
{1:~ }{3:│}{1:~ }{3:│}{1:~ }|
{3:[No Name] [+] < }{2:[No Name] [+] }|
|
]])
feed('<C-W>>')
screen:expect([[
aaa │ │ ^aaa |
│ │ |
a │ │ a |
aaaaaa │ │ aaaaaa |
~ │~│~ |
~ │~│~ |
~ │~│~ |
~ │~│~ |
[No Name] [+] < [No Name] [+] |
{4: }aaa {3:│}{4: }{3:│}{4: }^aaa |
{4: } {3:│}{4: }{3:│}{4: } |
{4: }a {3:│}{4: }{3:│}{4: }a |
{4: }aaaaaa {3:│}{4: }{3:│}{4: }aaaaaa |
{1:~ }{3:│}{1:~}{3:│}{1:~ }|
{1:~ }{3:│}{1:~}{3:│}{1:~ }|
{1:~ }{3:│}{1:~}{3:│}{1:~ }|
{1:~ }{3:│}{1:~}{3:│}{1:~ }|
{3:[No Name] [+] < }{2:[No Name] [+] }|
|
]])
feed('<C-W>h')
feed_command('set nowrap foldcolumn=4')
screen:expect([[
{4: }aaa {3:│}{4: }^aaa {3:│}{4: }aaa |
{4: } {3:│}{4: } {3:│}{4: } |
{4: }a {3:│}{4: }a {3:│}{4: }a |
{4: }aaaaaa {3:│}{4: }aaaaaa {3:│}{4: }aaaaaa |
{1:~ }{3:│}{1:~ }{3:│}{1:~ }|
{1:~ }{3:│}{1:~ }{3:│}{1:~ }|
{1:~ }{3:│}{1:~ }{3:│}{1:~ }|
{1:~ }{3:│}{1:~ }{3:│}{1:~ }|
{3:[No Name] [+] }{2:[No Name] [+] }{3:[No Name] [+] }|
:set nowrap foldcolumn=4 |
]])
feed('15<C-W><lt>')
screen:expect([[
{4: }aaa {3:│}{4: }{3:│}{4: }aaa |
{4: } {3:│}{4: }{3:│}{4: } |
{4: }a {3:│}{4: }{3:│}{4: }a |
{4: }aaaaaa {3:│}{4: ^ }{3:│}{4: }aaaaaa |
{1:~ }{3:│}{1:~ }{3:│}{1:~ }|
{1:~ }{3:│}{1:~ }{3:│}{1:~ }|
{1:~ }{3:│}{1:~ }{3:│}{1:~ }|
{1:~ }{3:│}{1:~ }{3:│}{1:~ }|
{3:[No Name] [+] }{2:<[+] }{3:[No Name] [+] }|
:set nowrap foldcolumn=4 |
]])
feed('4<C-W><lt>')
screen:expect([[
{4: }aaa {3:│}{4: }{3:│}{4: }aaa |
{4: } {3:│}{4: }{3:│}{4: } |
{4: }a {3:│}{4: }{3:│}{4: }a |
{4: }aaaaaa {3:│}{4:^ }{3:│}{4: }aaaaaa |
{1:~ }{3:│}{1:~}{3:│}{1:~ }|
{1:~ }{3:│}{1:~}{3:│}{1:~ }|
{1:~ }{3:│}{1:~}{3:│}{1:~ }|
{1:~ }{3:│}{1:~}{3:│}{1:~ }|
{3:[No Name] [+] }{2:< }{3:[No Name] [+] }|
:set nowrap foldcolumn=4 |
]])
end)
end)