-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Undo/Redo for a text based customEditor isn't working #9344
Comments
Hi, I think I'm having a similar issue although I'm not sure if it fits in this issue. We have custom editors (no text editor) and the undo/redo shortcuts don't trigger the right command handler for the active custom editor. It works if I add the undo/redo commands to the toolbar or trigger them by any other means than the shortcuts. I looked into it a bit and found that when using the keybinding, the monaco command handler for undo is always enabled, even though there is no focused monaco editor, so our custom handler never get called. See https://github.com/eclipse-theia/theia/blob/master/packages/monaco/src/browser/monaco-command.ts#L170 I'd like to provide a fix for this but I'm not sure if these monaco command handlers should only be enabled for focused monaco editors. If we use active editors as well (referring to monaco-command.ts#L170) if I activate my custom editor and there's a text editor opened (but hidden), it's still using that monaco command handler even though the text editor widget is technically not active. |
Hi @vince-fugnitto Do you have any feedback on that? |
@Hanksha I haven't looked into the details but I believe the problematic check is |
@vince-fugnitto Alright thanks, I'll look into it. |
@vince-fugnitto I think it was done this way so it can imitate the behavior of VS Code where you can undo/redo on the last active text editor without being focus on it, from example from the explorer view. I think what we want here is to use the monaco command handler as a default if nothing else could handle the command but I don't know if it's possible. |
@Hanksha I don't think we have prioritized handlers for keybindings, but you may be able to use a when-clause context (when a custom-editor is active) to register handlers for For reference I believe vscode does the following https://github.com/microsoft/vscode/blob/726b7f51e0063b065436be42aaee4853447143d8/src/vs/workbench/contrib/customEditor/browser/customEditors.ts#L84-L93. |
@vince-fugnitto Is that CustomEditorService available for theia extensions? I'm not using the vscode plugin API at all. |
@Hanksha I'm just pointing out what vscode does, if you aren't using the plugin-api then what are you using? Sorry I'm confused since this issue is about |
@vince-fugnitto I'm writing a theia extension and using widgets as editors which are not text based (not vscode editors) and it has the same issue as using |
I'm not sure how your non-text based editor looks like or is implemented so I can't really comment on what might be the issue for undo/redo, or how undo/redo should work in such a case. Our |
Unfortunately I don't have an example that is not proprietary but here's what I use:
bind(WidgetFactory).toDynamicValue(ctx => ({
id: "myid",
createWidget: (options: MyCustomWidgetOptions) => {
const child = ctx.container.createChild();
child.bind(MyCustomWidgetOptions).toConstantValue(options);
return child.get(MyCustomWidget);
}
}));
@injectable()
export class MyCustomWidgetOpenHandler extends WidgetOpenHandler<MyCustomWidget> {
id = "myid";
label = "My Custom Widget";
canHandle(uri: URI): MaybePromise<number> {
if (some condition) return 1;
return 0;
}
protected createWidgetOptions(uri: URI): object {
return {
uri: uri.toString()
};
}
}
Once that widget is opened, the undo/redo keybindings don't work either because the handler registered by the monaco-command is always enabled. |
@vince-fugnitto I also found out that there are two commands registered for the undo keybinding:
For both the "when" is undefined so from what I saw the keybinding for "undo" gets triggered but not "core.undo". |
@Hanksha I'm not sure what behaviour you want when you execute |
@vince-fugnitto Wouldn't that mean that if the user want then to edit the keybinding for the undo/redo he'd have to do it for all the registered commands? |
@Hanksha do you mind opening a discussion instead, I think it's adding a lot of noise to this issue which is strictly about a VS Code |
@vince-fugnitto Sure. |
@vince-fugnitto Done #12474 |
Bug Description:
When opening a text based custom editor document and making changes - undo/redo is caught but doesn't work
Steps to Reproduce:
custom-editor-sample
fromvscode-extension-samples
cscratch
document and make changes to itctrl+z
or undo/redo from Edit menucscratch
document isn't updatedReferring to this document for instance:
![image](https://user-images.githubusercontent.com/71069170/114570417-7c4a7980-9c7e-11eb-9ad0-07f793c5a687.png)
Additional Information
The text was updated successfully, but these errors were encountered: