Automatically select a search match #9
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "select-match-on-commit"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
When the search query changes, it's common behaviour for the first match at or after the current selection to be selected.
This adds a new
findNextInclusivefunction, similar to the existingfindNextbut allowing a match at the starting position, and calls it when the search query changes. If the search query is not valid, or there are not matches, the selection is emptied.https://user-images.githubusercontent.com/75253002/155420290-c70b65e8-77ac-4eb7-9ddc-6ccb6896ef8e.mov
I'd be happy to make this behaviour configurable with an option, if the current behaviour is the desired default.
Typing in the search dialog should not change the editor selection, I think. Also, as a command,
findNextInclusivedoesn't seem very useful, since it will stay stuck on the current match if you execute it multiple times.This is the behaviour of the search dialog in Chrome, VS Code, PHPStorm, CodeSandbox (basically everything I've tested), and is what I expected to happen, but I'm happy to make it configurable with an option if you'd prefer it not to be the default.
That's a fair point, I can turn it into a regular function if it wouldn't be useful as a command.
As an option, I'd be okay with this. But note that, at least in VS Code, it's not starting at the current selection, it's starting at the point where the selection was at the start of the current query editing session (however that's defined), otherwise it'll still creep forward as you're editing, missing matches that were nearer to the start of the original selection.
Also, it looks like you're currently not actually updating the query state field anymore in the modified code.
Interesting, there seems to be a few distinct approaches to where each new query starts from.
Assuming the query to be replaced by either:
a) selecting the whole query and typing over it
or
b) selecting the whole query, pressing Backspace, then typing the new query
this is what I've observed:
[edited as more testing found that Ace actually has a distinct behaviour]
The second approach seems simpler and less surprising.
I've found an alternative way to do this using an
updateListenerextension, acting on thesetSearchQueryeffect, but it needs access to theQueryTypein order to callqueryType.nextMatch(tr.state.doc, from, from). Would it be possible to export agetSearchQueryTypemethod from thesearchextension?:I've updated the PR but it's still implementing the simplest "continue moving forwards" behaviour, now behind a config option.
As this is the behaviour I'm looking for, but perhaps shouldn't be the default, it feels like this would be better in a separate extension, in which case exporting a
getSearchQueryTypemethod would be the preferred option.If it helps, that
getSearchQueryTypemethod would also be useful for implementing an "n of n" counter in a custom search panel.QueryTypeis not currently part of the package's public interface, and doesn't seem very suitable for being made public. Would agetCursor(text: Text, from: number, to: number): Iterator<{from: number, to: number}>method onSearchQuerycover your use cases?Yes, it looks like
getCursorwould be sufficient.Please take a look at attached patch, and let me know if it allows you to do what you're trying to do.
That's working nicely now, thanks @marijnh.
Pull request closed