mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
fix(events): triggered WinScrolled when only skipcol changed (#19972)
fix(events): trigger WinScrolled when only skipcol changed
vim-patch:9.0.0304: WinScrolled is not triggered when only skipcol changes
Problem: WinScrolled is not triggered when only skipcol changes.
Solution: Add w_last_skipcol and use it. (closes vim/vim#10998)
670ab0334b
This commit is contained in:
@@ -1119,6 +1119,7 @@ int autocmd_register(int64_t id, event_T event, char *pat, int patlen, int group
|
|||||||
if (event == EVENT_WINSCROLLED && !has_event(EVENT_WINSCROLLED)) {
|
if (event == EVENT_WINSCROLLED && !has_event(EVENT_WINSCROLLED)) {
|
||||||
curwin->w_last_topline = curwin->w_topline;
|
curwin->w_last_topline = curwin->w_topline;
|
||||||
curwin->w_last_leftcol = curwin->w_leftcol;
|
curwin->w_last_leftcol = curwin->w_leftcol;
|
||||||
|
curwin->w_last_skipcol = curwin->w_skipcol;
|
||||||
curwin->w_last_width = curwin->w_width;
|
curwin->w_last_width = curwin->w_width;
|
||||||
curwin->w_last_height = curwin->w_height;
|
curwin->w_last_height = curwin->w_height;
|
||||||
}
|
}
|
||||||
|
@@ -1240,9 +1240,10 @@ struct window_S {
|
|||||||
colnr_T w_skipcol; // starting column when a single line
|
colnr_T w_skipcol; // starting column when a single line
|
||||||
// doesn't fit in the window
|
// doesn't fit in the window
|
||||||
|
|
||||||
// four fields that are only used when there is a WinScrolled autocommand
|
// five fields that are only used when there is a WinScrolled autocommand
|
||||||
linenr_T w_last_topline; ///< last known value for w_topline
|
linenr_T w_last_topline; ///< last known value for w_topline
|
||||||
colnr_T w_last_leftcol; ///< last known value for w_leftcol
|
colnr_T w_last_leftcol; ///< last known value for w_leftcol
|
||||||
|
colnr_T w_last_skipcol; ///< last known value for w_skipcol
|
||||||
int w_last_width; ///< last known value for w_width
|
int w_last_width; ///< last known value for w_width
|
||||||
int w_last_height; ///< last known value for w_height
|
int w_last_height; ///< last known value for w_height
|
||||||
|
|
||||||
|
@@ -341,6 +341,39 @@ func Test_WinScrolled_close_curwin()
|
|||||||
call delete('Xtestout')
|
call delete('Xtestout')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_WinScrolled_long_wrapped()
|
||||||
|
CheckRunVimInTerminal
|
||||||
|
|
||||||
|
let lines =<< trim END
|
||||||
|
set scrolloff=0
|
||||||
|
let height = winheight(0)
|
||||||
|
let width = winwidth(0)
|
||||||
|
let g:scrolled = 0
|
||||||
|
au WinScrolled * let g:scrolled += 1
|
||||||
|
call setline(1, repeat('foo', height * width))
|
||||||
|
call cursor(1, height * width)
|
||||||
|
END
|
||||||
|
call writefile(lines, 'Xtest_winscrolled_long_wrapped')
|
||||||
|
let buf = RunVimInTerminal('-S Xtest_winscrolled_long_wrapped', {'rows': 6})
|
||||||
|
|
||||||
|
call term_sendkeys(buf, ":echo g:scrolled\<CR>")
|
||||||
|
call WaitForAssert({-> assert_match('^0 ', term_getline(buf, 6))}, 1000)
|
||||||
|
|
||||||
|
call term_sendkeys(buf, 'gj')
|
||||||
|
call term_sendkeys(buf, ":echo g:scrolled\<CR>")
|
||||||
|
call WaitForAssert({-> assert_match('^1 ', term_getline(buf, 6))}, 1000)
|
||||||
|
|
||||||
|
call term_sendkeys(buf, '0')
|
||||||
|
call term_sendkeys(buf, ":echo g:scrolled\<CR>")
|
||||||
|
call WaitForAssert({-> assert_match('^2 ', term_getline(buf, 6))}, 1000)
|
||||||
|
|
||||||
|
call term_sendkeys(buf, '$')
|
||||||
|
call term_sendkeys(buf, ":echo g:scrolled\<CR>")
|
||||||
|
call WaitForAssert({-> assert_match('^3 ', term_getline(buf, 6))}, 1000)
|
||||||
|
|
||||||
|
call delete('Xtest_winscrolled_long_wrapped')
|
||||||
|
endfunc
|
||||||
|
|
||||||
func Test_WinClosed()
|
func Test_WinClosed()
|
||||||
" Test that the pattern is matched against the closed window's ID, and both
|
" Test that the pattern is matched against the closed window's ID, and both
|
||||||
" <amatch> and <afile> are set to it.
|
" <amatch> and <afile> are set to it.
|
||||||
|
@@ -5362,6 +5362,7 @@ void may_trigger_winscrolled(void)
|
|||||||
win_T *wp = curwin;
|
win_T *wp = curwin;
|
||||||
if (wp->w_last_topline != wp->w_topline
|
if (wp->w_last_topline != wp->w_topline
|
||||||
|| wp->w_last_leftcol != wp->w_leftcol
|
|| wp->w_last_leftcol != wp->w_leftcol
|
||||||
|
|| wp->w_last_skipcol != wp->w_skipcol
|
||||||
|| wp->w_last_width != wp->w_width
|
|| wp->w_last_width != wp->w_width
|
||||||
|| wp->w_last_height != wp->w_height) {
|
|| wp->w_last_height != wp->w_height) {
|
||||||
char winid[NUMBUFLEN];
|
char winid[NUMBUFLEN];
|
||||||
@@ -5375,6 +5376,7 @@ void may_trigger_winscrolled(void)
|
|||||||
if (win_valid_any_tab(wp)) {
|
if (win_valid_any_tab(wp)) {
|
||||||
wp->w_last_topline = wp->w_topline;
|
wp->w_last_topline = wp->w_topline;
|
||||||
wp->w_last_leftcol = wp->w_leftcol;
|
wp->w_last_leftcol = wp->w_leftcol;
|
||||||
|
wp->w_last_skipcol = wp->w_skipcol;
|
||||||
wp->w_last_width = wp->w_width;
|
wp->w_last_width = wp->w_width;
|
||||||
wp->w_last_height = wp->w_height;
|
wp->w_last_height = wp->w_height;
|
||||||
}
|
}
|
||||||
|
@@ -61,6 +61,20 @@ describe('WinScrolled', function()
|
|||||||
eq(3, eval('g:scrolled'))
|
eq(3, eval('g:scrolled'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('is triggered by scrolling on a long wrapped line #19968', function()
|
||||||
|
local height = meths.win_get_height(0)
|
||||||
|
local width = meths.win_get_width(0)
|
||||||
|
meths.buf_set_lines(0, 0, -1, true, {('foo'):rep(height * width)})
|
||||||
|
meths.win_set_cursor(0, {1, height * width - 1})
|
||||||
|
eq(0, eval('g:scrolled'))
|
||||||
|
feed('gj')
|
||||||
|
eq(1, eval('g:scrolled'))
|
||||||
|
feed('0')
|
||||||
|
eq(2, eval('g:scrolled'))
|
||||||
|
feed('$')
|
||||||
|
eq(3, eval('g:scrolled'))
|
||||||
|
end)
|
||||||
|
|
||||||
it('is triggered when the window scrolls in Insert mode', function()
|
it('is triggered when the window scrolls in Insert mode', function()
|
||||||
local height = meths.win_get_height(0)
|
local height = meths.win_get_height(0)
|
||||||
local lines = {}
|
local lines = {}
|
||||||
|
Reference in New Issue
Block a user