sublime_text
sublime_text copied to clipboard
the command palette doesn't trigger on_post_window_command
Summary
It seems that the commands in the command palette do not trigger on_post_window_command of EventListener. It can be demonstrated by the following simple event listener
class FoobarListener(EventListener):
def on_post_window_command(self, window, command, args):
print(command, args)
And open command palette and run "View: Toggle Side Bar"
Expected behavior
The console should print toggle_side_bar None
Actual behavior
The function is not triggered. On the other hand, using the shortcut super+K, super+B does trigger the print statement.
Steps to reproduce
As described in the summary
Environment
- Operating system and version:
- Mac OS 10.13.2 (17C88)
- Sublime Text: Dev Channel 3157
@keith-hall
Toggling the sidebar is only an demonstration of the bug/issue. It is not restricted to toggling sidebar, see the issue divmain/GitSavvy#900
apologies @randy3k, I thought perhaps it was just a case of some specific built in window commands not being logged when executed from the command palette, as similar things have been reported before IIRC.
related: https://github.com/SublimeTextIssues/Core/issues/2198
also confirmed on Windows, even the Package Control: Add Channel command palette entry to run the add_channel window command doesn't get picked up by the event listener for on_window_command or on_post_window_command.
Is this a regression?
it looks like it is related to the refactoring of the command palette.
It seems to work fine in build 3153, so yes, seems like a regression.
As an addendum, on_window_command is also not triggered for commands from the command palette, which also has the side effect of blocking the ability of an event listener to re-write a command before it's executed.
This can cause some unfortunate UX when you implement a replacement command for something and an event listener to seamless replace it, which works everywhere except in the command palette.
@OdatNurd
A workaround is to utilize a command self.window.run_command.
class GsEditSettingsCommand(WindowCommand):
"""
For some reasons, the command palette doesn't trigger `on_post_window_command` for
dev version of Sublime Text. The command palette would call `gs_edit_settings` and
subsequently trigger `on_post_window_command`.
"""
def run(self, **kwargs):
self.window.run_command("edit_settings", kwargs)
Here is another example: bug.zip
# plugin.py
import sublime_plugin
class ShouldWorkCommand(sublime_plugin.WindowCommand):
def run(self):
print('should work is running')
class A(sublime_plugin.EventListener):
def on_window_command(self, window, command_name, args):
if command_name == 'should_work':
print('should work command is about to run')
def on_post_window_command(self, window, command_name, args):
if command_name == 'should_work':
print('should work command was run')
// Default.sublime-commands
[
{
"caption": "Should work command",
"command": "should_work"
}
]
There is a Should work command in the command palette.
When invoked I expect the following output when the command is invoked:
should work command is about to run
should work is running
should work command was run
But the actual behavior is that I see is:
should work is running