Sublime Forum

Problems moving caret after autocomplete window closes

#1

I am trying to create separate up/down commands to select things inside the autocomplete box, to disambiguate from the ordinary up/down inside the editor—specifically, I would like the latter to act as if the autocomplete box had never popped up at all.

In so doing, I need a command that executes, e.g., “close autocomplete and go up one line”. I’m having problems with the “go up” part, after the autocomplete window is closed.

Here’s my code:

def move_up(view):
    view.run_command("move", {"by": "lines", "forward": False})

def hide_auto_complete(view):
    view.run_command("hide_auto_complete")

class CloseAutoCompleteAndGoUpCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        hide_auto_complete(self.view)
        move_up(self.view)

This only works as expected when the selected line in the autocomplete window is the first line of the window. Symmetrically, the inverted command…

def move_down(view):
    view.run_command("move", {"by": "lines", "forward": True})

class CloseAutoCompleteAndGoDownCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        hide_auto_complete(self.view)
        move_down(self.view)

…only works as expected when the selected line in the autocomplete window is the last line of the window.

Does someone have a clue what’s going on?

0 Likes

#2

I did a little bit of testing wherein I tried to just make a key binding that still executes the existing move command while autocomplete is open but that doesn’t work as one would expect either.

On the other hand, modifying your command as follows works:

class CloseAutoCompleteAndGoUpCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        hide_auto_complete(self.view)
        sublime.set_timeout(lambda: move_up(self.view))

The set_timeout without a timeout specified essentially schedules the lambda to be called as soon as this command finishes.

As such, my best guess would be that the arrow keys are perhaps hard coded to perform a specific action while the autocomplete popup is visible and the command to hide the popup followed by the movement command happens quickly enough that internal state hasn’t stabilized yet on the panel being closed, or something along those lines.

2 Likes

#3

Thank you this works indeed…

0 Likes