Sublime Forum

Event (on_text_command) - commit_completion command text

#1

Hello,

I am building a plugin that needs to execute some logic after the user performs a completion (commit_completion or insert_best_completion commands).

I am able to track where they perform the completion but how do I get the completion that they actually chose?

Basically, I need to be able to determine what text was returned from the completion.

Is there a way to do this?

Thanks!
-Max

0 Likes

Detect current selected autocompletion option
#2

The closest you could get is to store the first selection (notably its offset) before the command is run, and then to compare against the first selection after the command is run. If there are no fields in the completion (i.e. snippet-like $1) you’d have the inserted text with a view.substr call, but if it was … you’d be pretty much screwed.

The only way to “properly” do this would be to compare file contents before and after the operation. You could do some optimization for not checking the entire file, since restrictions apply, but it would not be nice. Maybe hope for it to be implemented in the future? (yeah ik)

You could create an issue for this here for better browsability: github.com/SublimeTextIssues/Core/issues

0 Likes

#3

Aww… bummer…

Yeah it is kinda frustrating for the commit_completion command event to not have the inserted text loaded yet. It has the text I use to pick the completion, but not the actual chosen text.

Maybe running a wait function or something would work?

And if I was to use a file difference comparison how would I know what was changed if multiple lines were affected at the same time?

EDIT::

Just found the post_text_command method in the API docs. I tried it and it didn’t do anything. Am I missing something?

0 Likes

#4

Yes, the function is actually named on_post_text_command, which would be in line with the other events. It’s a documentation error.

0 Likes