-
Notifications
You must be signed in to change notification settings - Fork 13
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
Context menu enhancements #94
Context menu enhancements #94
Conversation
context_demo.mp4Add additional context menu commands (also from external extension)New context menu commands can be contributed via the "menus": {
"webview/context": [
{
"command": "memory-inspector.show-advanced-display-options",
"group": "display@4",
"when": "webviewId === memory-inspector.memory"
}
] To restrict the context/menu to the memory inspector at the
Each cell can also apply value specific custom context keys e.g. In addition, the context is also available as command argument in the handler of the corresponding command. vscode.commands.registerCommand(MemoryWebview.ShowAdvancedDisplayConfigurationCommandType, async (ctx: WebviewMenuContext) => {
this.messenger.sendNotification(showAdvancedOptionsConfigurationType, ctx.messageParticipant, undefined);
}); In addition,the |
@@ -65,6 +70,7 @@ class App extends React.Component<{}, MemoryAppState> { | |||
columnContributionService.register(new AsciiColumn()); | |||
decorationService.register(variableDecorator); | |||
this.state = { | |||
messageParticipant: { type: 'webview', webviewId: '' }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably prefer that we make this field nullable, as the default value isn't actually meaningful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also thought about that. The question is then how do we handle the potential undefined
value?
This would mean the resulting global context object would conform to this interface.
export interface WebviewMenuContext {
messageParticipant?: WebviewIdMessageParticipant,
visibleColumns: string,
showRadixPrefix: boolean,
}
So in theory, in a command handler for a context menu command we would always have to check whether ctx.messageParticipant
is defined before sending a message to the webview. In practice this check is unnecessary, because the participant is only undefined on initial render and should be correctly set once the initial settings are transferred from the extension.
At some point we have to make the implicit assumption that the messageParticipant
is set to the correct/valid value.
If would rather not have this on the user facing side (i.e. command context)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. It's really just an artifact of the interaction between React and the webview lifecycle. I suppose the question is what it looks like to a user if the synchronization goes bad for some reason. Is it a no-op in the VSCode messenger package, or does it throw an error; if error, how transparent is it? Could we provide a better message if something did go wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I quickly tested this. Using an invalid webview will be handeled by vscode-messenger silently (or at least not with a direct user-facing error message). A simple error message is logged in the debug console but that's it.
The messageParticipant
is part of the inital settings notification that is dispached as soon as the webview is ready.
So in practice we can only end up with an invalid (emtpy id) messageParticipant
if
- The webview never sends the ready notification
- or something goes wrong when retrieving the display settings from the vscode configuration.
Both cases are very unlikely, and if they should occur we probably have more pressing concerns than the invalid messageParticipant
as the entire webview-extension communication flow is not working as expected.
If we want to consider these corner cases we should probably handle this on a more generic level e.g. freezing the webview and/or display a loading indicator until the initial settings are received. In addition, we could add timeout error handling for cases where the extension never receives the webviewReady
notification. But this should probably be tackled in a follow-up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failing silently in unlikely circumstances is good enough for me. I was worried that it would throw an error, and if VSCode encounters an unhandled error during command execution, it'll show a very ugly dialog. As long as we avoid that, I'm happy.
171c96d
to
a5654dd
Compare
Thanks for the swift review @colin-grant-work. I have reworked the entire approach for toggling columns. In addition, I created common |
a5654dd
to
50ad871
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm satisfied 👍. Only sticking point is the question of separate on/off vs. toggle commands for the columns, if you have an opinion @jreineckearm.
Functionality in this PR looks really good, @tortmayr !
I agree with @colin-grant-work that a single toggle would be probably better. Just wondering how difficult it would be to have something like this, where the context menu entry indicates the current toggle state via a check mark? A few comments from testing:
|
For now, it was only planned to allow editing directly by clicking on the groups and not through Cut/Copy and Paste. This would require us to concretize how we want to handle such behavior, e.g., what to do on invalid/less/more data and what the cut operation does?. Consequently, we can remove Cut and Paste without any problems from my side. |
I tried that initially, but unfortunately we are restricted by the limits of the VS Code API here. Theoretically it is possible to define We could use a workaround using text emojs to visualize the toggle state e.g. ☐ ☑ Note that since conditional labels are not supported this would still require two commands per column: {
"command": "memory-inspector.show-variables-column",
"title": "☐ Variables Column",
"category": "Memory",
"enablement": "webviewId === memory-inspector.memory"
},
{
"command": "memory-inspector.hide-variables-column",
"title": "☑ Variables Column",
"category": "Memory",
"enablement": "webviewId === memory-inspector.memory"
}
Looks like the not working context menu entries is a know issue for Windows. There is an open bugfix PR: microsoft/vscode#206529 and looking at the comments its about to get merged.
It's not possible to remove individual entries of the default copy/paste menu. But we could deactivate the default items completely by adding
This could be fixed easily fixed if necessary (i.e. if we don't opt for removing the cut command)
Looks like this behavior was indirectly introduced with the autofit PR #82. |
@tortmayr yes, it changes how the |
I'd suggest to remove cut and paste from the context menu. If having them at all, I'd limit that to when editing of a group is active. Would suggest to move that discussion to the according issue.
Thanks for explaining this in more detail. Sounds like it is not as straight forward. In which case we shouldn't force it now. Let's go with a single toggle command. The columns state is in fact quite obvious without it. Just would have been the sugar on top. :-)
Hm.....probably we should just remove all of them then? Do the keyboard shortcuts then still work?
How bad is the flickering in reality? What would I need to change locally to see the behavior you mean? |
You can easily test it by disabling the css provided here either in code or in the devtools 30ab368#diff-1bcd15bcaf7de0329d93551add5ee225916db13b63a0f94b3f486f3443512f57R26 Then decrease the width of the webview. If you are fast enough, a second row will be rendered briefly due to the word breaking. That happens because there is a delay between rendering and until our fitting executes. To be honest, it wasnt that bad. I would say, the copy operation is more of a deal breaker than that. However, we should still investigate the issue. |
TBF: I am having a hard time to reproduce the duplicate column with that local change. But I do see an improvement. Now I only have linebreaks after each column. I guess it will be harder to remove those as well so that there is only a linebreak on a new row? That's what I see when pasting two rows into a new VS Code text file after commenting out the class style that you pointed me to.
Interestingly, it behaves differently when I try to paste directly into this GitHub comment form. Looks like some underlying HTML is included?
|
50ad871
to
e05a90d
Compare
@jreineckearm The latest commit should address all open issues With this change we
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot, @tortmayr , works nicely now!
Enhances the memory webview to properly support context menu actions contributed via `webview/context` contribution point. This includes - Augmenting the webview components with `data-vscode-context` custom data properties. These properties are used to provide additional context info (as JSON string). The composed context is then available in `when` conditions from `webview/context` contributions and as command argument when executing the associated command. Provides the following context menu enhancements outlined in eclipse-cdt-cloud#51 - Quick access to window configuration by - providing show/hide entries for variable & ascii column - show/hide for radix prefix - `Show advanced Options` command to show the advanced settings overlay - Allow contributions from other extensions
Will be addressed with eclipse-cdt-cloud#99
cb702b1
to
d6242a6
Compare
@jreineckearm I have rebased the change to resolve conflicts and also removed the workaround/fix for the copy&paste behavior again. This will be addressed with #99. |
@tortmayr , sorry, the line breaks between columns are back with the latest push. :-( |
@colin-grant-work |
What it does
Enhances the memory webview to properly support context menu actions contributed via
webview/context
contribution point. This includesdata-vscode-context
custom data properties.These properties are used to provide additional context info (as JSON string). The composed context is then available in
when
conditions fromwebview/context
contributions and as command argument when executing the associated command.Provides the following context menu enhancements outlined in #51
If no text is selected the value of the selected datatable cell will be copied instead.
Show advanced Options
command to show the advanced settings overlayHow to test
Open a context menu in the memory webview. The display entries (Show/Hide xyz, Show Advanced Options) should always be visible and work as expected.
Open a context menu ontop of a variable entry in the
variables
column. TheTest variable context
entry should appear.On click it will print the following to the memory output channel:
memory-inspector.get-webview-selection
)(The
TestVariableContext
command/menu is a temporary menu to test the extension functionality during review and will be removed before merging)Review checklist
Reminder for reviewers