From 63a331c82f3f418758b696dbf388c9403faed054 Mon Sep 17 00:00:00 2001 From: Caleb John Date: Mon, 11 Jan 2021 15:17:34 -0700 Subject: [PATCH] Desktop: Fixes #4338: Some commands were no longer working (#4343) --- packages/lib/services/CommandService.ts | 6 +++++- .../lib/services/commands/ToolbarButtonUtils.ts | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/lib/services/CommandService.ts b/packages/lib/services/CommandService.ts index 0d543bfd286..e69af8bccb9 100644 --- a/packages/lib/services/CommandService.ts +++ b/packages/lib/services/CommandService.ts @@ -314,6 +314,8 @@ export default class CommandService extends BaseService { return (commandName.indexOf('editor.') === 0 || // These commands are grandfathered in, but in the future // all editor commands should start with "editor." + commandName === 'insertText' || + commandName === 'scrollToHash' || commandName === 'textCopy' || commandName === 'textCut' || commandName === 'textPaste' || @@ -328,7 +330,9 @@ export default class CommandService extends BaseService { commandName === 'textCheckbox' || commandName === 'textHeading' || commandName === 'textHorizontalRule' || - commandName === 'insertDateTime' + commandName === 'insertDateTime' || + commandName === 'selectedText' || + commandName === 'replaceSelection' ); } diff --git a/packages/lib/services/commands/ToolbarButtonUtils.ts b/packages/lib/services/commands/ToolbarButtonUtils.ts index 43f04db58b5..fab652e373a 100644 --- a/packages/lib/services/commands/ToolbarButtonUtils.ts +++ b/packages/lib/services/commands/ToolbarButtonUtils.ts @@ -33,6 +33,19 @@ export default class ToolbarButtonUtils { return this.service_; } + private isEditorCommand(commandName: string) { + return CommandService.isEditorCommand(commandName) && !( + // These commands are attached to the editor runtime, + // but they either handle focus themselves or don't need + // to focus the editor + commandName === 'textLink' || + commandName === 'insertText' || + commandName === 'scrollToHash' || + commandName === 'selectedText' || + commandName === 'replaceSelection' + ); + } + private commandToToolbarButton(commandName: string, whenClauseContext: any): ToolbarButtonInfo { const newEnabled = this.service.isEnabled(commandName, whenClauseContext); const newTitle = this.service.title(commandName); @@ -54,8 +67,7 @@ export default class ToolbarButtonUtils { enabled: newEnabled, onClick: async () => { void this.service.execute(commandName); - // WARNING: textLink is a special case because it handles it's own focus - if (CommandService.isEditorCommand(commandName) && commandName !== 'textLink') { + if (this.isEditorCommand(commandName)) { void this.service.execute('editor.focus'); } },