1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Desktop: Resolves #4759: Fixed editor focus issue when running command from palette (#4812)

This commit is contained in:
Aksh-Konda 2021-04-07 01:51:24 +05:30 committed by GitHub
parent c79c9c4c2f
commit c37c2256c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 29 deletions

View File

@ -1045,6 +1045,9 @@ packages/lib/services/UndoRedoService.js.map
packages/lib/services/WhenClause.d.ts
packages/lib/services/WhenClause.js
packages/lib/services/WhenClause.js.map
packages/lib/services/commands/EditorFocusUtil.d.ts
packages/lib/services/commands/EditorFocusUtil.js
packages/lib/services/commands/EditorFocusUtil.js.map
packages/lib/services/commands/MenuUtils.d.ts
packages/lib/services/commands/MenuUtils.js
packages/lib/services/commands/MenuUtils.js.map

3
.gitignore vendored
View File

@ -1032,6 +1032,9 @@ packages/lib/services/UndoRedoService.js.map
packages/lib/services/WhenClause.d.ts
packages/lib/services/WhenClause.js
packages/lib/services/WhenClause.js.map
packages/lib/services/commands/EditorFocusUtil.d.ts
packages/lib/services/commands/EditorFocusUtil.js
packages/lib/services/commands/EditorFocusUtil.js.map
packages/lib/services/commands/MenuUtils.d.ts
packages/lib/services/commands/MenuUtils.js
packages/lib/services/commands/MenuUtils.js.map

View File

@ -17,6 +17,7 @@ const HelpButton = require('../gui/HelpButton.min');
const { surroundKeywords, nextWhitespaceIndex, removeDiacritics } = require('@joplin/lib/string-utils.js');
const { mergeOverlappingIntervals } = require('@joplin/lib/ArrayUtils.js');
import markupLanguageUtils from '../utils/markupLanguageUtils';
import focusEditorIfEditorCommand from '@joplin/lib/services/commands/focusEditorIfEditorCommand';
const PLUGIN_NAME = 'gotoAnything';
@ -379,6 +380,7 @@ class Dialog extends React.PureComponent<Props, State> {
if (item.type === BaseModel.TYPE_COMMAND) {
void CommandService.instance().execute(item.id);
void focusEditorIfEditorCommand(item.id, CommandService.instance());
return;
}

View File

@ -1,5 +1,6 @@
import CommandService from '../CommandService';
import { stateUtils } from '../../reducer';
import focusEditorIfEditorCommand from './focusEditorIfEditorCommand';
const separatorItem = { type: 'separator' };
@ -33,30 +34,6 @@ export default class ToolbarButtonUtils {
return this.service_;
}
// Editor commands will focus the editor after they're executed
private isEditorCommand(commandName: string) {
return (commandName.indexOf('editor.') === 0 ||
// These commands are grandfathered in, but in the future
// all editor commands should start with "editor."
// WARNING: Some commands such as textLink are not defined here
// because they are more complex and handle focus manually
commandName === 'textCopy' ||
commandName === 'textCut' ||
commandName === 'textPaste' ||
commandName === 'textSelectAll' ||
commandName === 'textBold' ||
commandName === 'textItalic' ||
commandName === 'textCode' ||
commandName === 'attachFile' ||
commandName === 'textNumberedList' ||
commandName === 'textBulletedList' ||
commandName === 'textCheckbox' ||
commandName === 'textHeading' ||
commandName === 'textHorizontalRule' ||
commandName === 'insertDateTime'
);
}
private commandToToolbarButton(commandName: string, whenClauseContext: any): ToolbarButtonInfo {
const newEnabled = this.service.isEnabled(commandName, whenClauseContext);
const newTitle = this.service.title(commandName);
@ -78,9 +55,7 @@ export default class ToolbarButtonUtils {
enabled: newEnabled,
onClick: async () => {
void this.service.execute(commandName);
if (this.isEditorCommand(commandName)) {
void this.service.execute('editor.focus');
}
void focusEditorIfEditorCommand(commandName, this.service);
},
title: newTitle,
};

View File

@ -0,0 +1,8 @@
import CommandService from '../CommandService';
import isEditorCommand from './isEditorCommand';
export default async function focusEditorIfEditorCommand(commandName: string, commandService: CommandService) {
if (isEditorCommand(commandName)) {
await commandService.execute('editor.focus');
}
}

View File

@ -0,0 +1,25 @@
// Editor commands will focus the editor after they're executed
export default function isEditorCommand(commandName: string) {
if (!commandName) return false;
return (commandName.indexOf('editor.') === 0 ||
// These commands are grandfathered in, but in the future
// all editor commands should start with "editor."
// WARNING: Some commands such as textLink are not defined here
// because they are more complex and handle focus manually
commandName === 'textCopy' ||
commandName === 'textCut' ||
commandName === 'textPaste' ||
commandName === 'textSelectAll' ||
commandName === 'textBold' ||
commandName === 'textItalic' ||
commandName === 'textCode' ||
commandName === 'attachFile' ||
commandName === 'textNumberedList' ||
commandName === 'textBulletedList' ||
commandName === 'textCheckbox' ||
commandName === 'textHeading' ||
commandName === 'textHorizontalRule' ||
commandName === 'insertDateTime'
);
}