You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Evaluate focused context, not global context #55453
*out-of-scopePosted issue is not in scope of VS CodemenusMenu items and widget issuesunder-discussionIssue is under discussion for relevance, priority, approach
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).
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.
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.
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.
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.
*out-of-scopePosted issue is not in scope of VS CodemenusMenu items and widget issuesunder-discussionIssue is under discussion for relevance, priority, approach
Activity
sbatten commentedon Aug 20, 2018
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
getActionswith 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)
alexdima commentedon Aug 21, 2018
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
currentlyFocusedEditorCanUndoand 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 keycurrentlyFocusedEditorCanUndowill 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.sbatten commentedon Aug 21, 2018
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.
vscodebot commentedon Oct 10, 2019
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!