Open SabreCat opened 5 years ago
4. Provide a keyboard shortcut to quickly toggle "Only in Selection" off when you discover you don't want it
You can add this to your keymap:
'.platform-win32 .find-and-replace':
'ctrl-alt-s': 'find-and-replace:toggle-selection-option'
Then in the situation you describe where pressing Enter doesn't move past the first result, you can use this (or whatever keybinding you want) to disable Only in Selection
.
I would suggest on display of find/replace panel, if the user has something selected then it defaults the "Selection only" on. The user can then unselect text in the editor or unselect the "Selection only" as desired.
If you have the "Only in Selection" toggle enabled, then search the current buffer without any selection currently highlighted, the search automatically highlights the first result. This means that attempts to proceed to the next search match within the document fail, as the search then collapses to encompass only that first hit. It ends up being a nuisance behavior, as it never feels expected and requires that the user then toggle the search mode and start over.
It seems to be a bit worse than that, to me. Here's what I'm seeing, at least in Atom 1.56.0 on Linux x86_64 — behavior confirmed even with atom --safe
.
Even with a selection "Find" will collapse that selection to the first match when you search. Meaning you can only ever find the first hit in your selection, and as a bonus you also lose the selection.
"Find All" will degrade a bit more slowly, but still breaks:
Inspecting the DOM with the dev console, it seems that Atom does draw a distinction between .selection
s and .find-result
s, two distinct type of .highlight
<div>
s created as children of a <div class="highlights">
container.
<div class="highlights style="style="contain: strict; position: absolute;
overflow: hidden; user-select: none; height: 48279px; width: 920px;">
<!-- A mouse selection creates one or more (depending on the shape) of these: -->
<div class="highlight selection">...</div>
<!-- "Find All" creates, for N matches, N-1 of these: -->
<div class="highlight find-result">...</div>
<!-- And exactly one of these: -->
<div class="highlight current-result">...</div>
<!-- ...But it **also** replaces the previous selection with N of these: -->
<div class="highlight selection">...</div>
<!-- Whereas "Find" simply replaces the previous selection with
a single one of these, which follows the current-result: -->
<div class="highlight selection">...</div>
Because activating any "Find" command for some reason blows away the user's text selection in favor of selecting some or all of the results (even though those selections are redundant with the current-result
and/or find-result
highlights it also creates), having "Find in selection" enabled becomes instantly useless.
I would suggest on display of find/replace panel, if the user has something selected then it defaults the "Selection only" on. The user can then unselect text in the editor or unselect the "Selection only" as desired.
I would flip that around slightly, and make "Find in selection" default to the entire buffer, if nothing is selected. That way, the toggle for "Find in selection" never has to auto-enable, it can be persisted across uses of the find panel or even entire Atom sessions, and it effectively becomes a preference switch to activate/deactivate the search behavior you describe, just without the magical auto-enabling.
Reversing it like that means that people who never want "Find in selection" can just leave it toggled off, it'll stay toggled off, and nobody is ever forced to unselect text or toggle switches to scope search the way they want it.
@AzzaAzza69
I would suggest on display of find/replace panel, if the user has something selected then it defaults the "Selection only" on. The user can then unselect text in the editor or unselect the "Selection only" as desired.
Heh! I discovered there was an old plugin to do exactly that (atom-auto-replace-in-selection). Turns out, getting the logic right on that can be trickier than it seems.
(It's a common pattern to select something, copy, then pull up Find: and paste into it. A naive auto-find-in-selection implementation can break that pattern.)
Prerequisites
Description
If you have the "Only in Selection" toggle enabled, then search the current buffer without any selection currently highlighted, the search automatically highlights the first result. This means that attempts to proceed to the next search match within the document fail, as the search then collapses to encompass only that first hit. It ends up being a nuisance behavior, as it never feels expected and requires that the user then toggle the search mode and start over.
I frequently run into this as I tend to alternate between in-selection and full-document searches and search-replace ops.
Steps to Reproduce
Expected behavior:
Search moves from one hit to the next, as if you were in selection-agnostic search mode
Actual behavior:
The search finds the first hit, then stops and loops over that result repeatedly
Reproduces how often:
100%
Versions
Atom : 1.40.1 Electron: 3.1.10 Chrome : 66.0.3359.181 Node : 10.2.0
Atom : 1.40.1 Electron: 3.1.10 Chrome : 66.0.3359.181 Node : 10.2.0
Windows 10 Home version 1809
Additional Information
Some possible solutions or mitigating changes: