Vim icon indicating copy to clipboard operation
Vim copied to clipboard

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

Open SamVSam opened this issue 1 year ago • 7 comments

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.

SamVSam avatar May 12 '23 17:05 SamVSam

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.

mikaelmedina avatar Sep 25 '23 12:09 mikaelmedina

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

HenryTSZ avatar Nov 27 '23 08:11 HenryTSZ

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 avatar Nov 27 '23 09:11 mikaelmedina

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).

mikaelmedina avatar Nov 27 '23 10:11 mikaelmedina

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 avatar May 06 '24 12:05 SamVSam

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 avatar May 07 '24 11:05 SamVSam

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.

SamVSam avatar May 08 '24 13:05 SamVSam