Sublime Forum

How to detect when the user closed the `goto_definition` box?

#1

How to detect when the user closed the goto_definition box?

This is the goto_definition I am talking about:

–>

I need to disable my plugin/package while that box is opened switching files, because my plugin is restoring the last position I had on the file.

This is the full code:

  1. https://github.com/evandrocoan/BufferScroll/blob/44bf81bff1300e13eae8b9f0436209c667ad433b/BufferScroll.py#L845-L849

Initially I could set a time out of 10 seconds to stop the plugin from doing it, but this is not optimal, I can close it before that and try to open something, or I could take longer than 10 seconds to pick up a file on the goto_definition box.

0 Likes

#2

seems pretty simple to me, unless I’m missing something

EDIT: yes, I am - it is possible to click outside the goto definition input box and the quick panel stays visible, so this won’t work in that case, and on_close isn’t fired when the quick panel really is closed. If you just care about when the user is typing in this view, it should be enough to ignore the quick panel view in your plugin because the id doesn’t seem to get reused. But, I’m not sure how to tell when it has been closed, without making changes to Packages/Default/symbols.py which I wouldn’t recommend :frowning:

import sublime
import sublime_plugin


class GotoDefinitionListener(sublime_plugin.EventListener):
    pre_definition_view = None
    definition_view = None
    
    def on_window_command(self, window, command_name, args):
        if command_name in ('goto_definition', 'context_goto_definition'):
            self.pre_definition_view = window.active_view().id()
    
    def on_activated(self, view):
        if self.pre_definition_view is not None:
            print('this view is the goto_definition input view', view.id(), 'activated from view', self.pre_definition_view)
            self.definition_view = view.id()
            self.pre_definition_view = None
        elif self.definition_view is not None and self.definition_view != view.id():
            print('the goto_definition input view was just deactivated')
            self.definition_view = None
2 Likes

#3

Thanks for time. Currently I implemented a time out of 10 seconds. I will also add your hook as complementary.

  1. https://github.com/evandrocoan/BufferScroll/blob/5d56f08c51b4daf68b5622c0b81b46d7c05b2b98/BufferScroll.py#L890
0 Likes