Skip to content

Evaluate focused context, not global context #55453

Closed

Description

Testing #55389

Extracted from #54510 (comment)

SteVen Batten (@sbatten) I tried to use precondition to control the enablement of Undo and Redo. One of the problems that came up is that the menubar menu entries are evaluated in the global context.

But in the workbench you can have multiple editors opened, some of which can undo and some of which cannot.

I have noticed that the menubar will refocus on the previously focused element when invoking the action, so if focus is in editor1, and then the Edit menu is opened, and Undo picked, focus is correctly brought back to editor1 before the command is invoked.

I think we could support high fidelity disablement/enablement of these commands if the menu items precondition would be evaluated in the context of the previous focused element. You can find the context associated with a particular element via IContextKeyService.getContext(previousFocusedElement).

Activity

  1. sbatten commented on Aug 20, 2018

    @sbatten
    Member

    alexandrudima

    This has more implications than originally considered.

    This first issue is that our menu registration system currently requires us to create a new menu to change the context of the actions (in order to determine enablement/disablement). We could change this so that we can call getActions with a another context, but we'd need to know when to call it to update the menu. You could say that we could use the lazy loading approach by only loading the menu actions when the user clicks the menu. In fact this would reduce the amount of listening the menubar would have to nearly 0 as we could just get the correct state of the menu right before we draw it. All this sounds well and good until we consider the native menubar. In this case, we can't be lazy, the menu has to be populated because we can't install a new menu as the user clicks into it and we have to send the menu over IPC.

    /cc Benjamin Pasero (@bpasero) Johannes Rieken (@jrieken)

  2. added
    under-discussion
    on Aug 20, 2018
  3. alexdima commented on Aug 21, 2018

    @alexdima
    MemberAuthor

    SteVen Batten (@sbatten) I don't understand how evaluating in the focused context is any different (or poses any more difficulties) than evaluating in the global context (what I understand the menu system does today).

    I can create a global context key called currentlyFocusedEditorCanUndo and manually track the focus in the page via some focus listener and when the focus lands in an editor I can find that editor and check if it has an undo stack. So, the global context key currentlyFocusedEditorCanUndo will be updated on each focus change. If the menus respect the global context, then the menus need to take this change into account and constantly repaint as the global context key is changed.

  4. sbatten commented on Aug 21, 2018

    @sbatten
    Member

    alexandrudima you are right about being able to map this to a global key that would solve the first problem which is that context is set when we create the menu (not show the menu).

    however, another concern has been raised especially with mac, that the menu is listening a lot for context and being frequently updated as you mention at the end. if we continue adding more context, i'm afraid we will have similar struggles as last milestone where the native menus feel like a huge perf regression.

  5. added
    menus
    *out-of-scope
    and removed on Oct 7, 2019
  6. vscodebot commented on Oct 10, 2019

    @vscodebot

    This issue is being closed to keep the number of issues in our inbox on a manageable level, we are closing issues that are not going to be addressed in the foreseeable future: We look at the number of votes the issue has received and the number of duplicate issues filed. More details here. If you disagree and feel that this issue is crucial: We are happy to listen and to reconsider.

    If you wonder what we are up to, please see our roadmap and issue reporting guidelines.

    Thanks for your understanding and happy coding!

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

Metadata

Metadata

Labels

*out-of-scopemenusunder-discussion

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions