Skip to content

changing curwin in callback results in scrolling for 'nosplitscroll'#11185

Closed
luukvbaal wants to merge 1 commit intovim:masterfrom
luukvbaal:splitscroll
Closed

changing curwin in callback results in scrolling for 'nosplitscroll'#11185
luukvbaal wants to merge 1 commit intovim:masterfrom
luukvbaal:splitscroll

Conversation

@luukvbaal
Copy link
Contributor

@luukvbaal luukvbaal commented Sep 21, 2022

changing curwin in callback results in scrolling for 'nosplitscroll'

Problem: w_valid flags are not updated accordingly for 'nosplitscroll', missing test for terminal mode callback.
Solution: Let validate_cursor handle w_valid flags except for VALID_TOPLINE, add callback tests.

This fixes scrolling when the current window is changed inside a callback as I alluded to in: #11166

Moreover, if we move the wincmd k to the callback function, the current fix is not enough to catch that and scrolling will still happen. Trying to fix it with a watchpoint on firstwin->w_topline and backtracing led me to trying to add workarounds in redraw_after_callback() or ex_docmd.c but it got quite complicated. Not sure if it's worth to catch this issue.

If we now catch all possible cases that could result in scrolling due to a user script callback I'm fine with this patch. I however can't be 100% certain that that is the case. I did try various other split/window commands inside the callback script and the added test keeps passing. I'm sure some user will report this issue at some point so up to you if you think this is a valid patch @brammool. Also adds missing test for the terminal mode callback patch added previously.

@codecov
Copy link

codecov bot commented Sep 21, 2022

Codecov Report

Merging #11185 (35ddba8) into master (f87eeb4) will decrease coverage by 0.55%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master   #11185      +/-   ##
==========================================
- Coverage   81.81%   81.25%   -0.56%     
==========================================
  Files         162      162              
  Lines      188698   188667      -31     
  Branches    42907    42888      -19     
==========================================
- Hits       154374   153298    -1076     
- Misses      21774    22925    +1151     
+ Partials    12550    12444     -106     
Flag Coverage Δ
huge-clang-none 82.67% <100.00%> (-0.01%) ⬇️
huge-gcc-none 54.63% <100.00%> (+<0.01%) ⬆️
huge-gcc-testgui 53.07% <100.00%> (+<0.01%) ⬆️
huge-gcc-unittests 0.29% <0.00%> (ø)
linux 82.49% <100.00%> (+<0.01%) ⬆️
mingw-x64-HUGE 76.48% <100.00%> (-0.01%) ⬇️
mingw-x86-HUGE ?
windows 76.48% <100.00%> (-1.65%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/window.c 88.91% <100.00%> (-0.03%) ⬇️
src/vimrun.c 0.00% <0.00%> (-50.00%) ⬇️
src/gui_dwrite.cpp 1.19% <0.00%> (-44.74%) ⬇️
src/xpm_w32.c 0.00% <0.00%> (-38.47%) ⬇️
src/gui_w32.c 24.19% <0.00%> (-12.86%) ⬇️
src/os_mswin.c 40.93% <0.00%> (-8.32%) ⬇️
src/os_win32.c 51.17% <0.00%> (-6.32%) ⬇️
src/winclip.c 59.91% <0.00%> (-4.55%) ⬇️
src/gui.c 69.53% <0.00%> (-3.36%) ⬇️
src/highlight.c 78.90% <0.00%> (-2.15%) ⬇️
... and 34 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

set splitscroll&
endfunc

source screendump.vim
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is usually put at the top at the file.

@brammool
Copy link
Contributor

brammool commented Sep 21, 2022 via email

@luukvbaal
Copy link
Contributor Author

Is there a way to add a condition, that something changed in the window layout, cursor position, etc? Actually, the current mechanism to only invalidate botline (w_valid flags VALID_BOTLINE and VALID_BOTLINE_AP) should already take care of this.

If you leave out the "invalidate_botline_win()" call, then what fails? Perhaps the solution is to call invalidate_botline() in some situation and there check for 'splitscroll' to be false.

It seems botline is not (in)validated before the window is entered, inside the callback. Thus, leaving it out results in win_fix_cursor() using an outdated value to determine whether topline < cursor.lnum < botline. I'm not sure if this outdated botline could be considered a bug or if it's because vim (without 'nosplitscroll') doesn't care about botline being up-to-date during a callback?
I can look into it once more.

@brammool
Copy link
Contributor

brammool commented Sep 21, 2022 via email

@luukvbaal
Copy link
Contributor Author

luukvbaal commented Sep 21, 2022

Just above the cursor is moved, thus removing VALID_CROW makes a lot of
sense.

Here we are actually just changing it temporarily(to scroll to bottom) and restoring it. So invalidating it here still doesn't quite make sense I think.

This is all getting quite complicated, we should really try to use the
"w_valid" flags in a proper way, otherwise we just keep updating values
that don't need updating.

Yes, I'm not sure why the check_cursor_moved() call in comp_botline() does not invalidate it. I guess it has to do with the fact that we delay moving the cursor in a window until it is entered(such that the cursor is not needlessly moved if the window layout changes again before it is entered). I'll try to make sense of the W_VALID flags and see if I can figure out where we need to set which in win_fix_cursor/scroll.

@luukvbaal
Copy link
Contributor Author

Latest commit lets the validate_cursor() call in win_new_height() handle the w_valid flags, except for VALID_TOPLINE because we update the cursor position in win_fix_cursor instead. I think this patch now makes sense and it prevents the scrolling that happened in the test case.

@luukvbaal
Copy link
Contributor Author

Scratch that, I thought I was doing a bitwise OR. Looking into it once more...

Problem:	Changing curwin in callback results in scrolling
for 'nosplitscroll', missing test for terminal mode callback.
Solution:	Invalidate w_crow for curwin, add callback tests.
@luukvbaal
Copy link
Contributor Author

luukvbaal commented Sep 23, 2022

This is the best I could come up with. It fixes the test case and I don't see any issues but I can't say I'm confident that w_valid flags are updated properly for 'nosplitscroll'.

@brammool brammool closed this in 20e5856 Sep 23, 2022
@brammool
Copy link
Contributor

brammool commented Sep 23, 2022 via email

zeertzjq added a commit to luukvbaal/neovim that referenced this pull request Oct 6, 2022
vim-patch:9.0.0445: when opening/closing window text moves up/down

Problem:    When opening/closing window text moves up/down.
Solution:   Add the 'splitscroll' option.  When off text will keep its
            position as much as possible.
vim/vim@29ab524

vim-patch:9.0.0455: a few problems with 'splitscroll'

Problem:    A few problems with 'splitscroll'.
Solution:   Fix 'splitscroll' problems. (Luuk van Baal, closes vim/vim#11117)
vim/vim@5ed3917

vim-patch:9.0.0461: 'scroll' is not always updated

Problem:    'scroll' is not always updated.
Solution:   Call win_init_size() at the right place.
vim/vim@470a141

vim-patch:9.0.0465: cursor moves when cmdwin is closed when 'splitscroll' is off

Problem:    Cursor moves when cmdwin is closed when 'splitscroll' is off.
Solution:   Temporarily set 'splitscroll' when jumping back to the original
            window. (closes vim/vim#11128)
vim/vim@e697d48

vim-patch:9.0.0469: cursor moves if cmdwin is closed when 'splitscroll' is off

Problem:    Cursor moves if cmdwin is closed when 'splitscroll' is off.
Solution:   Skip win_fix_cursor if called when cmdwin is open or closing.
            (Luuk van Baal, closes vim/vim#11134)
vim/vim@3735f11

vim-patch:9.0.0478: test for 'splitscroll' takes too much time

Problem:    Test for 'splitscroll' takes too much time.
Solution:   Only test some of the combinations. (Luuk van Baal, closes vim/vim#11139)
vim/vim@594f9e0

vim-patch:9.0.0486: text scrolled with 'nosplitscroll', autocmd win and help

Problem:    Text scrolled with 'nosplitscroll', autocmd win opened and help
            window closed.
Solution:   Skip win_fix_scroll() in more situations. (Luuk van Baal,
            closes vim/vim#11150)
vim/vim@d5bc762

vim-patch:9.0.0505: various problems with 'nosplitscroll'

Problem:    Various problems with 'nosplitscroll'.
Solution:   Fix 'nosplitscroll' problems. (Luuk van Baal, closes vim/vim#11166)
vim/vim@faf1d41

vim-patch:9.0.0555: scrolling with 'nosplitscroll' in callback changing curwin

Problem:    Scrolling with 'nosplitscroll' in callback changing curwin.
Solution:   Invalidate w_cline_row in the right place. (Luuk van Baal,
            closes vim/vim#11185)
vim/vim@20e5856

vim-patch:9.0.0603: with 'nosplitscroll' folds are not handled correctly

Problem:    With 'nosplitscroll' folds are not handled correctly.
Solution:   Take care of closed folds when moving the cursor. (Luuk van Baal,
            closes vim/vim#11234)
vim/vim@7c1cbb6

vim-patch:9.0.0605: dump file missing

Problem:    Dump file missing.
Solution:   Add the missing dump file. (issue vim/vim#11234)
vim/vim@439a2ba

vim-patch:9.0.0647: the 'splitscroll' option is not a good name

Problem:    The 'splitscroll' option is not a good name.
Solution:   Rename 'splitscroll' to 'splitkeep' and make it a string option,
            also supporting "topline". (Luuk van Baal, closes vim/vim#11258)
vim/vim@13ece2a

vim-patch:9.0.0667: ml_get error when 'splitkeep' is "screen"

Problem:    ml_get error when 'splitkeep' is "screen". (Marius Gedminas)
Solution:   Check the botline is not too large. (Luuk van Baal,
            closes vim/vim#11293, closes vim/vim#11292)
vim/vim@346823d
zeertzjq pushed a commit to neovim/neovim that referenced this pull request Oct 6, 2022
vim-patch:9.0.0445: when opening/closing window text moves up/down

Problem:    When opening/closing window text moves up/down.
Solution:   Add the 'splitscroll' option.  When off text will keep its
            position as much as possible.
vim/vim@29ab524

vim-patch:9.0.0455: a few problems with 'splitscroll'

Problem:    A few problems with 'splitscroll'.
Solution:   Fix 'splitscroll' problems. (Luuk van Baal, closes vim/vim#11117)
vim/vim@5ed3917

vim-patch:9.0.0461: 'scroll' is not always updated

Problem:    'scroll' is not always updated.
Solution:   Call win_init_size() at the right place.
vim/vim@470a141

vim-patch:9.0.0465: cursor moves when cmdwin is closed when 'splitscroll' is off

Problem:    Cursor moves when cmdwin is closed when 'splitscroll' is off.
Solution:   Temporarily set 'splitscroll' when jumping back to the original
            window. (closes vim/vim#11128)
vim/vim@e697d48

vim-patch:9.0.0469: cursor moves if cmdwin is closed when 'splitscroll' is off

Problem:    Cursor moves if cmdwin is closed when 'splitscroll' is off.
Solution:   Skip win_fix_cursor if called when cmdwin is open or closing.
            (Luuk van Baal, closes vim/vim#11134)
vim/vim@3735f11

vim-patch:9.0.0478: test for 'splitscroll' takes too much time

Problem:    Test for 'splitscroll' takes too much time.
Solution:   Only test some of the combinations. (Luuk van Baal, closes vim/vim#11139)
vim/vim@594f9e0

vim-patch:9.0.0486: text scrolled with 'nosplitscroll', autocmd win and help

Problem:    Text scrolled with 'nosplitscroll', autocmd win opened and help
            window closed.
Solution:   Skip win_fix_scroll() in more situations. (Luuk van Baal,
            closes vim/vim#11150)
vim/vim@d5bc762

vim-patch:9.0.0505: various problems with 'nosplitscroll'

Problem:    Various problems with 'nosplitscroll'.
Solution:   Fix 'nosplitscroll' problems. (Luuk van Baal, closes vim/vim#11166)
vim/vim@faf1d41

vim-patch:9.0.0555: scrolling with 'nosplitscroll' in callback changing curwin

Problem:    Scrolling with 'nosplitscroll' in callback changing curwin.
Solution:   Invalidate w_cline_row in the right place. (Luuk van Baal,
            closes vim/vim#11185)
vim/vim@20e5856

vim-patch:9.0.0603: with 'nosplitscroll' folds are not handled correctly

Problem:    With 'nosplitscroll' folds are not handled correctly.
Solution:   Take care of closed folds when moving the cursor. (Luuk van Baal,
            closes vim/vim#11234)
vim/vim@7c1cbb6

vim-patch:9.0.0605: dump file missing

Problem:    Dump file missing.
Solution:   Add the missing dump file. (issue vim/vim#11234)
vim/vim@439a2ba

vim-patch:9.0.0647: the 'splitscroll' option is not a good name

Problem:    The 'splitscroll' option is not a good name.
Solution:   Rename 'splitscroll' to 'splitkeep' and make it a string option,
            also supporting "topline". (Luuk van Baal, closes vim/vim#11258)
vim/vim@13ece2a

vim-patch:9.0.0667: ml_get error when 'splitkeep' is "screen"

Problem:    ml_get error when 'splitkeep' is "screen". (Marius Gedminas)
Solution:   Check the botline is not too large. (Luuk van Baal,
            closes vim/vim#11293, closes vim/vim#11292)
vim/vim@346823d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants