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

Various search related fixes #883

Merged
merged 31 commits into from
May 28, 2024

Conversation

citizenmatt
Copy link
Member

@citizenmatt citizenmatt commented May 12, 2024

This PR fixes various search related issues.

Search highlights:

  • Fix :set hlsearch not re-enabling highlights after :nohlsearch (VIM-3257)
  • Fix search highlights not visible in diff view. Highlights are now shown in all visible editors, including diff and tool windows, and an editor's highlights are updated when the editor gains focus (VIM-2174)
  • Fix regression in new regex engine not highlighting current search match when confirming each substitution with the :substitute/{pattern}/{string}/c command
  • Fix 'incsearch' and 'nohlsearch' adding highlights to other windows. It should only highlight the current match in the current editor to match Vim's behaviour
  • Fix search highlight colour not updating when editor scheme changes
  • Fix incorrectly forcing 'ignorecase' for search highlights, ignoring passed in case sensitivity atom (VIM-3391)
  • Fix search highlight that crosses newline not being removed
  • Fix infinite loop in old regex engine when highlighting the identifier atom (it would treat the end of line character as an identifier character!) (VIM-2510)

Incremental search:

  • Fix search command line input breaking due to incsearch trying to highlight outside the range of other visible windows. The range is now coerced to fit the editor being highlighted. Also added try/catch to incsearch to prevent other exceptions breaking ex entry (VIM-3325)
  • Fix incremental search navigating to the wrong offset for the current match (VIM-2779)

Search behaviour:

  • Add support for [count]/ in search (VIM-2836)
  • Fix motion type when using search as a motion and providing offset or e flag. Default motion is exclusive. Providing the e flag changes it to inclusive, and an offset makes it linewise (VIM-1940)
  • Fix search for last search pattern with new offset - typing //e now works (VIM-2356)
  • Fix incorrectly resetting last substitution string when it's used - e.g. :%s/foo/~ would use the last substitution string, but also reset it to an empty string. It's now only reset when it's a value other than ~ (VIM-3354)
  • Fix regression with new regex engine not saving and reusing previously saved patterns (VIM-3348)
  • Fix regression with new regex to support /e flag to navigate to end of search result (VIM-3344)
  • Fix regression with new regex when substitute command string ends with backslash (VIM-3428)
  • Fix bug in old regex engine that would skip forward too far with multiline patterns and miss matches. Also fixes bug in new regex to match newline at end of file (VIM-698)
  • Fix bug in old regex engine to handle end of file atom (\%$) (VIM-2888)
  • Fix both regex engines for multiline regex substitution (VIM-2141)
  • Fix selection being incorrectly reset when searching in Visual mode. It should be updated based on search results
  • Fix highlighting of current match in substitute command not scrolling a result on the last line of the file to be visible above the ex entry field (VIM-1560)
  • Fix highlighting of current match on last line being obscured by "transparent" scrollbars on Windows + Linux (VIM-3028)

Misc:

  • Add status bar message when search wraps. Updated status bar message handling to clear on "redraw", like Vim - clear on scroll, add/remove lines, showing ex entry, etc. (VIM-1043)
  • Fix / or : commands not registering if ex entry is cancelled by losing focus (VIM-3293)

Regression while migrating to the new regex engine removed the highlights shown when confirming each change
Setting 'incsearch' and 'nohlsearch' should highlight only the current match in the current editor
Search motion type should be linewise if there's a line offset, or inclusive if the `e` flag is provided. Otherwise, it's exclusive.

Fixes VIM-1940
This is a messy quick fix, as the search group needs a lot of tidying up right now. Perhaps a better implementation would be to move the implementation of the global command into the search group - processGlobalCommand, like we already have processSearchCommand and processSubstituteCommand

Fixes VIM-3348
Substitute always works on a known range
Also implements <C-L> to "redraw" screen and clear status line
When performing a substitute command with confirmation, the height of the editor content pane should be reduced by the height of the ex entry panel. IdeaVim would do this correctly when moving a search result to the bottom of the file, but not when the result was on the last line of the file. Because the wrong height was used, IdeaVim would decide that no scrolling was necessary and the result in the last line would be obscured.

Fixes VIM-1560
@AlexPl292 AlexPl292 merged commit 7865388 into JetBrains:master May 28, 2024
2 checks passed
@AlexPl292
Copy link
Member

Thank you for all the great updates and fixes!

I have only one question about the first commit. Are you sure that using overrideOption is the correct approach for fixing this issue? Also, returning always true from the setGlobalValue seems to break the contract that says that "Returns true if the applied new value is different to the current stored value", isn't it?

@citizenmatt citizenmatt deleted the bugfix/misc-search-fixes branch May 28, 2024 11:33
@citizenmatt
Copy link
Member Author

I guess it is a little bit of a fudge, but it's not one I'm too bothered about. The override mechanism is there to modify behaviour, although the main use case is mapping to an external IDE setting, so I'm ok with it being used to change the behaviour of change notifications.

The boolean returned from setGlobalValue is really there so we can optimise listeners, so that they're not called unnecessarily during window initialisation, and it's not exposed to anyone outside of VimOptionGroup. So it's a soft contract between layers in an internal implementation rather than a contract for user code. It's intended to say - the value has changed, so call the listeners, and I use the override to modify behaviour to say "thanks for calling setGlobalValue, please call listeners". It's a bit of a fudge, but not too bad.

What is interesting is that I didn't realise that autocmd has an OptionSet event that provides Vim arguments for old/new value, etc. I am very tempted to add autocmd support and reimplement the existing listeners on top of this (probably as hidden commands, as it would be an implementation detail). And these commands are called even when the value hasn't changed. But I'm going to try to resist doing anything with options right now 😁

E.g.:

autocmd OptionSet hlsearch echo v:option_command . " " . expand('<amatch>') . " " . v:option_new . " " . v:option_old

@AlexPl292
Copy link
Member

Wow, I didn't know about autocmd OptionSet either.
Well, the autocmd ticket is 4th from the top, so we're not far away from it ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants