Sublime Forum

sublime_plugin.EventListener works differently on command call from menu/hotkey and command palette/console

#1

Hello everyone!
I occured strange problem and I don’t know yet if this is a ST (3210) bug or my own fault.

I’m developing a plugin that works in background and must be stopped when appropriate command is given.
So I’m using sublime_plugin.EventListener.on_post_text_command to change environment when expected command was executed.
And it works normally when I call the command from the main menu / by the hot keys.
But on_post_text_command never triggers when I run the command from Command Palette (which is a comfort way to control the plugin) or from console (like sublime.run_command('highlime_pause')).

So does anybody know why execution of command from Command Palette or from console may not trigger on_post_text_command?

Here is a short reproducible code snippet ("Highlime paused" is printed every time on highlime_pause call but “GOTCHA!” won’t be printed if command was called from Palette/console):

import sublime
import sublime_plugin

PLUGIN_ACTIVATED = False


# Listener to stop the plugin when requested:
class HighlimePauseCommandListener(sublime_plugin.EventListener):

    def on_post_text_command(self, view, command_name, args):
        if command_name == 'highlime_pause':
            print('GOTCHA!')
            global PLUGIN_ACTIVATED
            PLUGIN_ACTIVATED = False

# Command to signalize that we want to stop the plugin:
class HighlimePauseCommand(sublime_plugin.TextCommand):

    def run(self, edit):
        print('Highlime paused')
0 Likes

#2

I think there are some bugs whereby invoking commands from the Command Palette don’t get picked up by the EventListener - this one is for WindowCommands, but maybe it also affects TextCommands?

0 Likes

#3

That’s looks just like this, yes - thank you!
I think I should create new issue for it with related links.

UPD:

0 Likes