Sublime Forum

Can I auto-highlight the "Replace With" field on focus?

#1

When using the Find and Replace pane, the Find What field is auto-selected when I press Ctrl+H. This allows me to quickly change the value in said field. However, when I press the Tab key to move focus to the Replace With field, the text is not auto-selected. As a result, I have to either select all text with Ctrl+A or the mouse, remove it, then type what I want in the field.

Is there a way I can get the contents of the Replace With field to be automatically selected when it receives focus? That would allow me to just start typing to replace the contents of that field, saving me some time.

1 Like

#2

you could do something like this:

import sublime
import sublime_plugin


class SelectAllOnFocusEventListener(sublime_plugin.EventListener):
    def on_activated(self, view):
        if view.window().get_view_index(view) == (-1, -1):
            if len(view.sel()) == 1:
                if view.sel()[0].empty():
                    view.sel().clear()
                    view.sel().add(sublime.Region(0, view.size()))

but it wouldn’t just be restricted to the replace field - AFAIK there is no way to detect it - so it would operate on any view that doesn’t have a “group / tab index” assigned by the window.

if the Regex Format Widget.sublime-settings file worked (see https://github.com/SublimeTextIssues/Core/issues/1079), then it would be trivial to add a unique setting to determine if it is the replace field or not.

0 Likes

#3

I think there must be some kind of bug here. Try this:

Start ST (this is 3126 on Windows) and press Ctrl+H.
The “Find What” value is selected.
Press Tab and the “Replace With” value is selected. That is, it works as OP wants.
Now, click the “Replace With” field with the mouse.
The selection disappears - as expected.
Close the Find/Replace dialog using Esc and open it again using Ctrl+H.
The auto-select in the “Replace With” field no longer works.
After restarting ST, auto-select works again.

0 Likes

#4

when ST is launched, and the find and replace panel is opened for the first time, the text in both the find and the replace with textboxes are automatically selected. After using/closing and re-opening the panel, they retain their prior selections.

0 Likes

#5

I would love a solution for this. It drives me crazy.

0 Likes