In a sublime_plugin.TextCommand if the plugin is run using a key binding from within a panel or overlay is it possible for the plugin to switch focus from the overlay or panel to the text of the document?
Ideally if called from the overlay or find/replace panel then the overlay or panel would be closed when the focus changes to the text of the document, but if called from the console then the console would be left open.
I tried the following but it didn’t work - I guess the view already has the focus so it changes nothing and an overlay or panel being displayed does not actually mean the view has lost focus.
if self.view.settings().get('is_widget'):
window = self.view.window()
window.focus_view(window.active_view())
I’m trying to do something similar - because it really annoys me, that double clicking on an error in the Build Results panel, to jump to the text in the main view where the error occurred, doesn’t focus the main view, and doesn’t show where the cursor is in the main view. (Yes, it shows the line if you have "highlight_line": true, set in your preferences, but for debugging syntax tests, I want to see the column too without closing the panel - so I can still see the scopes from the syntax test results.
So I’ve written this:
import sublime
import sublime_plugin
class GotoBuildResultEventListener(sublime_plugin.EventListener):
def on_post_text_command(self, view, command_name, args):
if command_name == 'drag_select' and args.get('by', None) == 'words':
window = view.window()
if view.id() != window.active_view().id():
if window.active_panel() == 'output.exec':
window.focus_view(window.active_view())
but it doesn’t focus the main view, so I’m using what feels like a hacky workaround:
fortunately, it keeps the build results panel scrolled at the same place, although it’s now hard to tell where I was looking in the panel because of this:
anyway, rant over - hopefully this info will help someone that encounters the same problems as me
EDIT: note that the traditional view.settings().get('is_widget') method doesn’t work for the output panel, possibly due to this: