Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alex-pobeditel-2004 opened this issue Jun 12, 2020 · 2 comments

Comments

@alex-pobeditel-2004
Copy link

alex-pobeditel-2004 commented Jun 12, 2020

Hello!

It looks like sublime_plugin.EventListener does not see commands executed via Command Palette and from ST console. There is no problem with command calls from main menu / hotkeys though.

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')).

Tested on operating systems: Windows 10 / Arch Linux
Sublime Text builds: 3210, 4074

I tried not only on_post_text_command but also on_text_command - and together with issues #2234 and #2400 it looks like the problem is actual for all sublime_plugin.EventListener.on_*_command listeners.

Summary: Now it looks impossible to catch command call events from Command Palette or ST console so it may cause improper work of plugins (when the command is executed but the listener did not trigger)

Here is a short code snippet that can be used to reproduce a bug ("Highlime paused" is printed every time on highlime_pause command 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')

Forum topic where the history started: https://forum.sublimetext.com/t/sublime-plugin-eventlistener-works-differently-on-command-call-from-menu-hotkey-and-command-palette-console/52007

@FichteFoll
Copy link
Collaborator

Reproduced on 4074, Arch Linux. Below is what I ran in the console.

>>> view.run_command("highlime_pause")
Highlime paused
>>> window.run_command("highlime_pause")
Highlime paused
GOTCHA!

@alex-pobeditel-2004
Copy link
Author

Interesting. Does it mean that when we run command from Palette it is being executed for view but not for window?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants