This may be an itch that you can scratch with a plugin, such as the example below.
This plugin implements an event listener that detects when a find panel is about to open while another find panel is already visible, and clears the selection in the current view so that the new find panel doesn’t slurp it.
In cases where there is not already a panel visible, or a panel is visible but it’s the same panel that is about to be opened again, the selection is left as-is.
That lets you still select text and find it in the buffer or in files, but also ensures that if a find panel is already open and you open another one, the search string remains the same.
This could be enhanced to save the selection before it is cleared, and then have it be restored in an on_post_window_command
to be a more seamless operation, if desired.
You can give it a try by selecting Tools > Developer > New Plugin...
from the menu, replacing the stub plugin with the code below, then saving as a .py
file in the location that Sublime will default to (your User
package).
import sublime
import sublime_plugin
class ClearSelectionCommand(sublime_plugin.TextCommand):
"""
Clear all selections and return to a single caret in the current view.
"""
def run(self, edit):
if self.view.sel():
first_sel = self.view.sel()[0]
self.view.sel().clear()
self.view.sel().add(sublime.Region(first_sel.b))
class MyListener(sublime_plugin.EventListener):
"""
When a find panel opens in a window, clear the selection in its current
view if there is another find panel open.
"""
def on_window_command(self, window, command, args):
if command == "show_panel" and window.active_panel() is not None:
if args.get("panel", None) not in ("console", "output"):
window.active_view().run_command("clear_selection")