VSCodeVim / Vim

:star: Vim for Visual Studio Code
http://aka.ms/vscodevim
MIT License
13.9k stars 1.32k forks source link

Reverse search with `?` command makes the window shift downwards #3598

Open ASC95 opened 5 years ago

ASC95 commented 5 years ago

Describe the bug When I reverse-search using "?", the result is correctly found. However with large files, the window often (but not always) shifts downward so that the found pattern is displayed at the very top line of the window.

To Reproduce

  1. Open a file with significantly more lines that can fit in the visible window
  2. Scroll to around the middle of the file
  3. Place the cursor below a pattern you want to search for
  4. type $ ?\<pattern> $ in the command bar
  5. As you type \<pattern>, the window could shift to match whatever partial pattern you've already entered.
  6. Finish typing your \, and the window will jump back upwards to the match that it found above your cursor position.
  7. Even if \<pattern> was originally visible well within the bounds of your starting window, searching for it using "?" could cause the window to shift downwards as it finds matches to the partial pattern as you are typing. When you're done typing, the window finds the correct match, but places it at the top of the window as it shifts back upwards.
  8. The end result is that it appears the window pointlessly shifts downwards so that \<pattern> is displayed at the top of the window, when in reality the window shouldn't have moved at all.

Expected behavior I expect reverse-search "?" to behave the same as forward search "/" with regard to when the window shifts around.

When I forward-search for a pattern, the window only moves if the pattern is found outside of the visible range of the window. If the pattern is already in the visible window, then the cursor moves to the pattern and the window does not change.

When I reverse-search for a pattern, I want the same thing to happen. The window should only shift if the pattern does not exist in the visible window. Otherwise, the cursor should move to the pattern in the visible window and the window should not move at all.

Screenshots First image: I am forward-searching "/are" to highlight the pattern "are". That is the pattern I'm going to eventually search for using reverse search. Cursor is on line 43. image

Second image: I have typed"?a", which is part of the eventual search for "?are". The window has shifted elsewhere in my document as it matched "a". image

Third image: I have finished typing "?are", and the match on line 41 is now annoyingly displayed at the top of my window. What should have happened is that the window should not have moved at all (see image 1), but the cursor should have moved. image

Environment (please complete the following information): MacOS 10.14.6 VSCode version 1.32.3 VSCodeVim version 1.2.0

pelegm commented 2 years ago

I am not sure whether this is related, but it seems so, so instead of opening a new issue, I add it here: I'm at the end of this file. There's a bunch of appearances of e before my pointer. I press ? and then e. Instead of moving me to the closest appearance of e in my immediate neighbourhood, it bounces to some arbitrary point high above. It returns only after I continue for the second character. Check the gif.

Peek 2022-06-06 20-29