Skip to content

Commit

Permalink
fix #7525: rework monaco commands to align with VS Code
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Kosyakov <[email protected]>
  • Loading branch information
akosyakov committed Apr 9, 2020
1 parent aaa425b commit 3f5fe49
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 159 deletions.
71 changes: 45 additions & 26 deletions packages/core/src/browser/common-frontend-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ export namespace CommonCommands {
id: 'core.redo',
label: 'Redo'
};
export const SELECT_ALL: Command = {
id: 'core.selectAll',
label: 'Select All'
};

export const FIND: Command = {
id: 'core.find',
Expand Down Expand Up @@ -500,11 +504,22 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
}
});

commandRegistry.registerCommand(CommonCommands.UNDO);
commandRegistry.registerCommand(CommonCommands.REDO);
commandRegistry.registerCommand(CommonCommands.UNDO, {
execute: () => document.execCommand('undo')
});
commandRegistry.registerCommand(CommonCommands.REDO, {
execute: () => document.execCommand('redo')
});
commandRegistry.registerCommand(CommonCommands.SELECT_ALL, {
execute: () => document.execCommand('selectAll')
});

commandRegistry.registerCommand(CommonCommands.FIND);
commandRegistry.registerCommand(CommonCommands.REPLACE);
commandRegistry.registerCommand(CommonCommands.FIND, {
execute: () => { /* no-op */ }
});
commandRegistry.registerCommand(CommonCommands.REPLACE, {
execute: () => { /* no-op */ }
});

commandRegistry.registerCommand(CommonCommands.NEXT_TAB, {
isEnabled: () => this.shell.currentTabBar !== undefined,
Expand Down Expand Up @@ -577,7 +592,7 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
isEnabled: () => {
const currentWidget = this.shell.getCurrentWidget('main');
return currentWidget !== undefined &&
this.shell.mainAreaTabBars.some(tb => tb.titles.some(title => title.owner !== currentWidget && title.closable));
this.shell.mainAreaTabBars.some(tb => tb.titles.some(title => title.owner !== currentWidget && title.closable));
},
execute: () => {
const currentWidget = this.shell.getCurrentWidget('main');
Expand Down Expand Up @@ -705,6 +720,10 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
command: CommonCommands.REDO.id,
keybinding: 'ctrlcmd+shift+z'
},
{
command: CommonCommands.SELECT_ALL.id,
keybinding: 'ctrlcmd+a'
},
{
command: CommonCommands.FIND.id,
keybinding: 'ctrlcmd+f'
Expand Down Expand Up @@ -841,16 +860,16 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
this.quickOpenService.open({
onType: (_, accept) => accept(items)
}, {
placeholder: 'Select File Icon Theme',
fuzzyMatchLabel: true,
selectIndex: () => items.findIndex(item => item.id === this.iconThemes.current),
onClose: () => {
if (resetTo) {
previewTheme.cancel();
this.iconThemes.current = resetTo;
placeholder: 'Select File Icon Theme',
fuzzyMatchLabel: true,
selectIndex: () => items.findIndex(item => item.id === this.iconThemes.current),
onClose: () => {
if (resetTo) {
previewTheme.cancel();
this.iconThemes.current = resetTo;
}
}
}
});
});
}

protected selectColorTheme(): void {
Expand Down Expand Up @@ -880,19 +899,19 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
this.quickOpenService.open({
onType: (_, accept) => accept(items)
}, {
placeholder: 'Select Color Theme (Up/Down Keys to Preview)',
fuzzyMatchLabel: true,
selectIndex: () => {
const current = this.themeService.getCurrentTheme().id;
return items.findIndex(item => item.id === current);
},
onClose: () => {
if (resetTo) {
previewTheme.cancel();
this.themeService.setCurrentTheme(resetTo);
placeholder: 'Select Color Theme (Up/Down Keys to Preview)',
fuzzyMatchLabel: true,
selectIndex: () => {
const current = this.themeService.getCurrentTheme().id;
return items.findIndex(item => item.id === current);
},
onClose: () => {
if (resetTo) {
previewTheme.cancel();
this.themeService.setCurrentTheme(resetTo);
}
}
}
});
});
}

registerColors(colors: ColorRegistry): void {
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/common/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,17 @@ export class CommandRegistry implements CommandService {

/**
* Register the given handler for the given command identifier.
*
* If there is already a handler for the given command
* then the given handler is registered as more specific, and
* has higher priority during enablement, visibility and toggle state evaluations.
*/
registerHandler(commandId: string, handler: CommandHandler): Disposable {
let handlers = this._handlers[commandId];
if (!handlers) {
this._handlers[commandId] = handlers = [];
}
handlers.push(handler);
handlers.unshift(handler);
return {
dispose: () => {
const idx = handlers.indexOf(handler);
Expand Down
1 change: 0 additions & 1 deletion packages/monaco/src/browser/monaco-command-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export class MonacoCommandRegistry {
protected execute(monacoHandler: MonacoEditorCommandHandler, ...args: any[]): any {
const editor = this.monacoEditors.current;
if (editor) {
editor.focus();
return Promise.resolve(monacoHandler.execute(editor, ...args));
}
return Promise.resolve();
Expand Down
Loading

0 comments on commit 3f5fe49

Please sign in to comment.