Skip to content

Commit

Permalink
Wrong display with 'smoothscroll' when emptying quickfix list
Browse files Browse the repository at this point in the history
Problem:  Wrong display with 'smoothscroll' when emptying quickfix list.
Solution: Reset w_skipcol when w_topline is changed.
  • Loading branch information
zeertzjq committed May 8, 2024
1 parent fb74575 commit d337559
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/autocmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2393,7 +2393,7 @@ apply_autocmds_group(
// values are saved, restored by reset_lnums(). When nested only the
// values are corrected when needed.
if (nesting == 1)
check_lnums(TRUE);
check_lnums(TRUE, FALSE);
else
check_lnums_nested(TRUE);

Expand Down
2 changes: 1 addition & 1 deletion src/ex_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -3200,7 +3200,7 @@ do_ecmd(
}

// Check if cursors in other windows on the same buffer are still valid
check_lnums(FALSE);
check_lnums(FALSE, TRUE);

/*
* Did not read the file, need to show some info about the file.
Expand Down
1 change: 1 addition & 0 deletions src/move.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ update_topline(void)
redraw_later(UPD_NOT_VALID);
curwin->w_topline = 1;
curwin->w_botline = 2;
curwin->w_skipcol = 0;
curwin->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP;
curwin->w_scbind_pos = 1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/proto/window.pro
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ int tabline_height(void);
int last_stl_height(int morewin);
int min_rows(void);
int only_one_window(void);
void check_lnums(int do_curwin);
void check_lnums(int do_curwin, int adjust_skipcol);
void check_lnums_nested(int do_curwin);
void reset_lnums(void);
int make_snapshot(int idx);
Expand Down
2 changes: 1 addition & 1 deletion src/quickfix.c
Original file line number Diff line number Diff line change
Expand Up @@ -4952,7 +4952,7 @@ qf_fill_buffer(qf_list_T *qfl, buf_T *buf, qfline_T *old_last, int qf_winid)
}

// correct cursor position
check_lnums(TRUE);
check_lnums(TRUE, TRUE);

if (old_last == NULL)
{
Expand Down
20 changes: 20 additions & 0 deletions src/testdir/dumps/Test_smoothscroll_in_qf_window_1.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
> +0&#ffffff0@59
|~+0#4040ff13&| @58
|~| @58
|~| @58
|~| @58
|~| @58
|~| @58
|[+3#0000000&|N|o| |N|a|m|e|]| @50
|<+0#4040ff13&@2| +0#af5f00255&|2+0#0000000&|1| |2@1| |2|3| |2|4| |2|5| |2|6| |2|7| |2|8| |2|9| @29
| +0#af5f00255&@1|8| ||+0#0000000&@1| |0| |1| |2| |3| |4| |5| |6| |7| |8| |9| |1|0| |1@1| |1|2| |1|3| |1|4| |1|5| |1|6| |1|7| |1|8| |1|9| |2|0|
| +0#af5f00255&@3|2+0#0000000&|1| |2@1| |2|3| |2|4| |2|5| |2|6| |2|7| |2|8| |2|9| @29
| +0#af5f00255&@1|9| ||+0#0000000&@1| |0| |1| |2| |3| |4| |5| |6| |7| |8| |9| |1|0| |1@1| |1|2| |1|3| |1|4| |1|5| |1|6| |1|7| |1|8| |1|9| |2|0|
| +0#af5f00255&@3|2+0#0000000&|1| |2@1| |2|3| |2|4| |2|5| |2|6| |2|7| |2|8| |2|9| @29
| +0#af5f00255&|1|0| ||+0#0000000&@1| |0| |1| |2| |3| |4| |5| |6| |7| |8| |9| |1|0| |1@1| |1|2| |1|3| |1|4| |1|5| |1|6| |1|7| |1|8| |1|9| |2|0|
| +0#af5f00255&@3|2+0#0000000&|1| |2@1| |2|3| |2|4| |2|5| |2|6| |2|7| |2|8| |2|9| @29
| +0#af5f00255&|1@1| ||+0#0000000&@1| |0| |1| |2| |3| |4| |5| |6| |7| |8| |9| |1|0| |1@1| |1|2| |1|3| |1|4| |1|5| |1|6| |1|7| |1|8| |1|9| |2|0|
| +0#af5f00255&@3|2+0#0000000&|1| |2@1| |2|3| |2|4| |2|5| |2|6| |2|7| |2|8| |2|9| @29
| +0#af5f00255&|1|2| ||+0#0000000&@1| |b|a|r| @49
|[+1&&|Q|u|i|c|k|f|i|x| |L|i|s|t|]| @44
| +0&&@59
20 changes: 20 additions & 0 deletions src/testdir/dumps/Test_smoothscroll_in_qf_window_2.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
> +0&#ffffff0@59
|~+0#4040ff13&| @58
|~| @58
|~| @58
|~| @58
|~| @58
|~| @58
|[+3#0000000&|N|o| |N|a|m|e|]| @50
| +0#af5f00255&@1|1| | +0#0000000&@55
|~+0#4040ff13&| @58
|~| @58
|~| @58
|~| @58
|~| @58
|~| @58
|~| @58
|~| @58
|~| @58
|[+1#0000000&|Q|u|i|c|k|f|i|x| |L|i|s|t|]| @44
|:+0&&|c|a|l@1| |s|e|t|q|f|l|i|s|t|(|[|]|,| |'|r|'|)| @35
20 changes: 20 additions & 0 deletions src/testdir/dumps/Test_smoothscroll_in_qf_window_3.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
> +0&#ffffff0@59
|~+0#4040ff13&| @58
|~| @58
|~| @58
|~| @58
|~| @58
|~| @58
|[+3#0000000&|N|o| |N|a|m|e|]| @50
| +0#af5f00255&@1|1| ||+0#0000000#ffff4012@1| |f|o@1| @49
| +0#af5f00255#ffffff0@1|2| ||+0#0000000&@1| |0| |1| |2| |3| |4| |5| |6| |7| |8| |9| |1|0| |1@1| |1|2| |1|3| |1|4| |1|5| |1|6| |1|7| |1|8| |1|9| |2|0|
| +0#af5f00255&@3|2+0#0000000&|1| |2@1| |2|3| |2|4| |2|5| |2|6| |2|7| |2|8| |2|9| @29
| +0#af5f00255&@1|3| ||+0#0000000&@1| |0| |1| |2| |3| |4| |5| |6| |7| |8| |9| |1|0| |1@1| |1|2| |1|3| |1|4| |1|5| |1|6| |1|7| |1|8| |1|9| |2|0|
| +0#af5f00255&@3|2+0#0000000&|1| |2@1| |2|3| |2|4| |2|5| |2|6| |2|7| |2|8| |2|9| @29
| +0#af5f00255&@1|4| ||+0#0000000&@1| |0| |1| |2| |3| |4| |5| |6| |7| |8| |9| |1|0| |1@1| |1|2| |1|3| |1|4| |1|5| |1|6| |1|7| |1|8| |1|9| |2|0|
| +0#af5f00255&@3|2+0#0000000&|1| |2@1| |2|3| |2|4| |2|5| |2|6| |2|7| |2|8| |2|9| @29
| +0#af5f00255&@1|5| ||+0#0000000&@1| |0| |1| |2| |3| |4| |5| |6| |7| |8| |9| |1|0| |1@1| |1|2| |1|3| |1|4| |1|5| |1|6| |1|7| |1|8| |1|9| |2|0|
| +0#af5f00255&@3|2+0#0000000&|1| |2@1| |2|3| |2|4| |2|5| |2|6| |2|7| |2|8| |2|9| @29
| +0#af5f00255&@1|6| ||+0#0000000&@1| |0| |1| |2| |3| |4| |5| |6| |7| |8| |9| |1|0| |1@1| |1|2| |1|3| |1|4| |1|5| |1|6| |1|7| |1|8| |1|9| |@+0#4040ff13&@2
|[+1#0000000&|Q|u|i|c|k|f|i|x| |L|i|s|t|]| @44
|:+0&&|c|a|l@1| |s|e|t|q|f|l|i|s|t|(|g|:|l|,| |'|r|'|)| @34
27 changes: 27 additions & 0 deletions src/testdir/test_scroll_opt.vim
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,33 @@ func Test_smoothscroll_insert_bottom()
call StopVimInTerminal(buf)
endfunc

func Test_smoothscroll_in_qf_window()
CheckScreendump

let lines =<< trim END
set nocompatible display=lastline
copen
setlocal number smoothscroll
let g:l = [{'text': 'foo'}]
\ + repeat([{'text': join(range(30))}], 10)
\ + [{'text': 'bar'}]
call setqflist(g:l, 'r')
normal! G
wincmd t
END
call writefile(lines, 'XSmoothScrollInQfWindow', 'D')
let buf = RunVimInTerminal('-u NONE -S XSmoothScrollInQfWindow', #{rows: 20, cols: 60})
call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_1', {})

call term_sendkeys(buf, ":call setqflist([], 'r')\<CR>")
call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_2', {})

call term_sendkeys(buf, ":call setqflist(g:l, 'r')\<CR>")
call VerifyScreenDump(buf, 'Test_smoothscroll_in_qf_window_3', {})

call StopVimInTerminal(buf)
endfunc

func Test_smoothscroll_in_zero_width_window()
set cpo+=n number smoothscroll
set winwidth=99999 winminwidth=0
Expand Down
13 changes: 9 additions & 4 deletions src/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -7540,7 +7540,7 @@ only_one_window(void)
* Implementation of check_lnums() and check_lnums_nested().
*/
static void
check_lnums_both(int do_curwin, int nested)
check_lnums_both(int do_curwin, int nested, int adjust_skipcol)
{
win_T *wp;
tabpage_T *tp;
Expand All @@ -7566,7 +7566,11 @@ check_lnums_both(int do_curwin, int nested)

need_adjust = wp->w_topline > curbuf->b_ml.ml_line_count;
if (need_adjust)
{
wp->w_topline = curbuf->b_ml.ml_line_count;
if (adjust_skipcol)
wp->w_skipcol = 0;
}
if (need_adjust || !nested)
// save the (corrected) topline
wp->w_save_cursor.w_topline_corr = wp->w_topline;
Expand All @@ -7577,11 +7581,12 @@ check_lnums_both(int do_curwin, int nested)
* Correct the cursor line number in other windows. Used after changing the
* current buffer, and before applying autocommands.
* When "do_curwin" is TRUE, also check current window.
* When "adjust_skipcol" is TRUE, reset w_skipcol if w_topline changes.
*/
void
check_lnums(int do_curwin)
check_lnums(int do_curwin, int adjust_skipcol)
{
check_lnums_both(do_curwin, FALSE);
check_lnums_both(do_curwin, FALSE, adjust_skipcol);
}

/*
Expand All @@ -7590,7 +7595,7 @@ check_lnums(int do_curwin)
void
check_lnums_nested(int do_curwin)
{
check_lnums_both(do_curwin, TRUE);
check_lnums_both(do_curwin, TRUE, FALSE);
}

/*
Expand Down

0 comments on commit d337559

Please sign in to comment.