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

[CLOSED] Can’t use console API from within an extension command handler #9130

Open
core-ai-bot opened this issue Aug 30, 2021 · 4 comments

Comments

@core-ai-bot
Copy link
Member

Issue by sbruchmann
Sunday Jan 04, 2015 at 06:00 GMT
Originally opened as adobe/brackets#10305


This is strange. Take a look at the following code of a sample extension:

define(function () {
    "use strict";

    var AppInit = brackets.getModule("utils/AppInit");
    var CommandManager = brackets.getModule("command/CommandManager");
    var Menus = brackets.getModule("command/Menus");

    function main() {
        CommandManager.register("test", "com.example.test", test);
        Menus.getMenu(Menus.AppMenuBar.FILE_MENU).addMenuItem("com.example.test");
    }

    function test() {
        console.log("hello world");
    }

    AppInit.appReady(main);
});

In case you don’t know, the code above registers a new command and adds a menu item to File menu as soon as Brackets is ready. The command logs "hello world" to the console.

The problem is, that the command handler (test()) doesn’t get executed when triggered via the menu item as soon as it contains a call to the console API. Substituting console.log("hello world") with $("#main-toolbar").toggle() works. Calling test() directly works as expected, no matter what is being executed inside of test.

There are no errors logged to the console and Brackets did behave as usual afterwards. I’ve yet to find a way to debug this.

‘Reload without extensions’ is not applicable here, so I’ve temporarily disabled all user extensions.

System Setup:

  • OS X 10.9.5
  • Brackets Release 1.2 development build 1.2.0-0 (master da48369fb)
  • Brackets Shell d9b1cae

Edit: Fixed copy & paste error as mentioned in this comment.

@core-ai-bot
Copy link
Member Author

Comment by busykai
Sunday Jan 04, 2015 at 06:16 GMT


COMMAND_ID is undefined. If changed to "com.example.test" works perfectly for me.

@core-ai-bot
Copy link
Member Author

Comment by sbruchmann
Sunday Jan 04, 2015 at 06:18 GMT


@busykai Oops, this was just a copy & paste error. Still doesn’t work for me.

@core-ai-bot
Copy link
Member Author

Comment by sbruchmann
Sunday Jan 04, 2015 at 06:26 GMT


To make things a tad weirder as before: Adding a key binding to the menu item executes the command handler. Invoking the menu item directly is still not working.

@core-ai-bot
Copy link
Member Author

Comment by sbruchmann
Sunday Jan 04, 2015 at 06:35 GMT


Damn, I found the culprit! He was sitting 10 inches in front of the screen…

The problem was that I invoked the command while devtools were focused. It’s too early on a Sunday morning (GMT) ;). Closing.

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

No branches or pull requests

1 participant