junegunn/vim-slash

`*` incorrectly restores view due to wrapped lines

nkouevda opened this issue · 0 comments

Problem

If e.g. 1) the first line in the window is wrapped, 2) the cursor is on any line below that, and 3) * would cause the view to move down (i.e. the next match is not yet visible), then winline() - s:winline will usually compute an incorrect sdiff, and we will <C-y> more times than necessary, shifting the view up by at least 1 line (unless we were already at the beginning of the buffer, or there are some other edge cases).

Possible solution

I believe using winsaveview()['topline'] instead of winline() avoids this discrepancy between buffer lines and screen lines.

I'll put up a PR with that approach, but 1) I'm not sure if there's a simpler way to get topline (maybe some function I overlooked?), and 2) although I've tested this with all edge cases that I'm aware of, I can't be sure that this entirely fixes this issue, or that it doesn't break anything else.