Sublime Forum

Return focus to editor

#1

I’m writing a plugin that runs a selection of commands when menu buttons are pressed, and captures the output into the Console window (the one shown with ctrl+`).

So in my plugin:

    # setup 
    # ... 
    # now show the panel
    self.view.window().run_command("show_panel", {"panel": "console" })
    # now run the command
    # ...
    # now return focus to the editor
    self.view.window().focus_group(0)

However, if I’ve got multiple Tab groups (by switching with alt+shift+2, for example) and I’m in the second pane, this always returns focus to group 0 (because that’s what I’ve asked the function to do…)

Is there a way to make it return focus to the same one that gets focussed if I close the console (with Esc)?

Thanks!

0 Likes

How to focus Sublime Text *across the OS*
#2

I think you’ll just need to get the active view:

sublime.Window.active_view
0 Likes

#3

window.focus_group(window.active_group()) should do what you’re after

0 Likes

#4

That’s fantastic. I’m sure I tried something like that before, but must have got the incantation slightly wrong…

Thank you!

(ps, I’m so impressed by your support jps - truly brilliant editor with a great community, and a tentative dev. Can’t ask for more!)

0 Likes