Sublime Forum

Command-line tab to replace field in Replace panel

#1

I have been trying to write bash scripts that run Sublime commands. I can’t seem to find any way to make my scripts tab from the Find field to the Replace field in the Replace panel when it has focus.

subl --command ‘show_panel { “panel”: “replace” }’ myFile.txt

The above opens the Replace panel, but is there a way to open this panel so the Replace field has cursor focus?

0 Likes

#2

I’m not sure this is possible, I had a go at writing a plugin to try to select the replace field (which would only work if only one ST window is open I guess) but was unsuccessful. Here was my attempt:

import sublime
import sublime_plugin


class FocusReplaceInputCommand(sublime_plugin.WindowCommand):
    def run(self):
        #self.window.run_command('show_panel', { 'panel': 'replace' })
        replace_input_view = sublime.View(8)
        self.window.focus_view(replace_input_view)
        print(replace_input_view.size())
        #print(replace_input_view.settings().get('syntax', None))
        print(replace_input_view.substr(sublime.Region(0, replace_input_view.size())))
        vector = replace_input_view.text_to_window(0)
        print(vector)
        #self.window.run_command('drag_select', { "event": {"button": 1, "x": vector[0], "y": vector[1] } })

unfortunately, it seems like 8 may not be the correct view despite having the correct syntax applied (it doesn’t seem to be the find in files one either). The position is always reported as 0, 0, the contents blank etc. and the focus isn’t switched as desired.

0 Likes

#3

I tried to run the command:

'insert { “characters”: “\t” }

but this just inserted an actual tab in the Find field. However, when I press tab myself when in the Replace panel, it will switch focus to the Replace field. Do you think there is a way to get Sublime to interpret “\t” to switch focus instead of inserting a tab?

0 Likes