Sublime Forum

Auto complete selection index (implement "Go-to snippet definition")

#1

Hello.
I have a long list of custom snippets I have defined in different sub-directories.

When the list above is shown, I’d like to navigate snippets, then press alt+enter to go to the snippet definition / file.

I am able to map a key-binding to invoke when the completions list above is shown:

{ "keys": ["alt+enter"], 
  "command": "goto_snippet_definition",
  "context": [ { "key": "auto_complete_visible" }] },

…but I don’t know how to tell my plugin which was the line which was highlighted right before calling the plugin. I believe that what I need is the selection index, something similar to show_quick_panel()'s on_select() / on_highlight callbacks (link).

FWIW, I have noticed ST by default defines a command which is able to do something like this.

{ "keys": ["f12"], "command": "auto_complete_open_link", "context":
	[
		{ "key": "auto_complete_visible", "operator": "equal", "operand": true },
	]
},

The above key-binding allows you to press “F12” while navigating the completions list and show you something different each time, so theoretically this appears possible.

Thanks in advance.

0 Likes

#2

Completions panels don’t support callbacks like on_select(), mainly for performance reasons, I guess.

auto_complete_open_link command opens the first link in a completion’s details field.

I am not aware of sublime-snippet files to be able to define kind info or details field however.

2 Likes

#3

Thanks for chiming in @deathaxe. I suspected this was not possible.

It must receive the reference of the highlighted item or index somehow though. Unfortunately there’s no source code for auto_complete_open_link.
auto_complete and commit_completion commands seem “special” in the same fashion.

0 Likes

#4

All of them are API commands, implemented in ST core.

You could try to file a feature request, but an on_selected() like API is IMHO quite unlikely to be added. It has been discussed several times in the past.

1 Like