Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlighted search results loses highlighting after switching to another tab and back #8416

Open
SamVSam opened this issue May 12, 2023 · 7 comments

Comments

@SamVSam
Copy link

SamVSam commented May 12, 2023

Describe the bug
Highlighted search results loses highlighting after switching to another tab and back to initial where searching occurred.

To Reproduce
Steps to reproduce the behavior:

  1. Add/use/have these lines in settings.json (colors can be anything, but visible):
    "vim.hlsearch": true,
    "vim.searchHighlightColor": "#ffff88",
  2. Open several files in several tabs;
  3. Search for any word that is in file, with any type of vim search, like with / or ? in command line or with * in normal mode while cursor is on the necessary word (word becomes highlighted with color defined in settings);
  4. Swtch to any other tab and back to the initial one where search happened, bug happens with any type of switching, i.e. with mouse or ctrl+tab/ctrl+shift+tab or with :tabn/:tabp commands;
  5. See that searched word is not highlighted anymore + highlighting disappears for other tabs if searched word exists there too. In addition n/shift+n finds next/previous occurances, but w/o highlighting.

Expected behavior
Searched word should stay highlighted in all open tabs where word exist until other search occurs or until :noh command is executed;

Environment (please complete the following information):

  • Extension (VsCodeVim) version: 1.25.2
  • VSCode version: 1.78.2
  • OS: Ubuntu 20.04.4 (Linux x64 5.4.0-148-generic)
  • OS: macOS Monterey 12.5.1

Additional context
Important to mention - running any command or empty command (: + return) or even canceling empty command (: + esc) restores highlighting, unitl next switching between tabs.

@mikaelmedina
Copy link

This is the one that bugs me:

In addition n/shift+n finds next/previous occurances, but w/o highlighting.

The first matched word is highlighted according to "vim.searchMatchColor", but pressing n/shift+n just removes the current match highlight, but jumps correctly.

@HenryTSZ
Copy link
Contributor

I merged this PR and roughly used it, but found two issues:

  1. When I searched in tab 1, the highlighting was normal. When I switched to tab 2, the same characters were highlighted normally, but when I switched back to tab 1, the highlighting disappeared;
  2. When I search for the fourth character in tab 1, in tab 2, the cursor is on the first character and the current selection is highlighted on the fourth character

selection2

@mikaelmedina
Copy link

My PR simply addresses highlighting the current match, and doesn't address the tab-switching aspect. I think the highlighting would be accurate again if you jump to the next match and back (n -> N). All though not optimal, my aim was to address the second part of OP's point 5, as that was the one that bugged me the most.

As for the tab switching I didn't really look into it that much, but I assume a call to updateSearchHighlights in the proper place could go a long way, I'll see if I can do something.

@mikaelmedina
Copy link

From some brief testing it appears that mode is reset to normal mode when switching views, as the ModeHandler is individual per document. Once you do enter search mode again, highlights are corrected. Fixing it would require that search mode persists when switching tab while in search mode, which is something that might be feasible, but not something I think I'll spend time on. To be fair I think that going into normal mode when I switch tab is desirable over staying in search mode (not that there is a big difference).

@SamVSam
Copy link
Author

SamVSam commented May 6, 2024

To be fair I think that going into normal mode when I switch tab is desirable over staying in search mode (not that there is a big difference).

I almost got used to run empty command to "turn on" highlighting in other tab. Other thing is that I have started doing so in ordinary vim. Which is completely not necessary. Ordinary vim keeps highlighting searched text across buffers/tabs/splits/etc till user runs :noh command.

Probably might use something like map <C-Tab> :tabn | noh | set hls <Enter> (converted to vscodevim configs) as workaround.

@SamVSam
Copy link
Author

SamVSam commented May 7, 2024

From some brief testing it appears that mode is reset to normal mode when switching views, as the ModeHandler is individual per document. Once you do enter search mode again, highlights are corrected.

BTW not really.
Highlights are corrected even if I run empty command (: + enter) or even if I cancel empty command (: + esc). So looks like problem is not only in ModeHandler being individual per document.

@SamVSam
Copy link
Author

SamVSam commented May 8, 2024

Out of sudden - highlighting disapperas even when I change zoom level (cmd+- and cmd+= on mac).
Also highlighting restores with going into insert mode and starting typing anything.

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

No branches or pull requests

3 participants