1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-06 09:19:22 +02:00

Plugins: Add command "editorSetText" for desktop app

This commit is contained in:
Laurent Cozic
2020-11-13 22:50:03 +00:00
parent 872d2942b4
commit aaaa4e4569
3 changed files with 21 additions and 4 deletions

View File

@@ -19,9 +19,10 @@ interface HookDependencies {
editorRef: any;
titleInputRef: any;
saveNoteAndWait: Function;
setFormNote: Function;
}
function editorCommandRuntime(declaration: CommandDeclaration, editorRef: any): CommandRuntime {
function editorCommandRuntime(declaration: CommandDeclaration, editorRef: any, setFormNote: Function): CommandRuntime {
return {
execute: async (_context: CommandContext, ...args: any[]) => {
if (!editorRef.current.execCommand) {
@@ -39,6 +40,10 @@ function editorCommandRuntime(declaration: CommandDeclaration, editorRef: any):
type: ScrollOptionTypes.Hash,
value: args[0],
});
} else if (declaration.name === 'editorSetText') {
setFormNote((prev: FormNote) => {
return { ...prev, body: args[0] };
});
} else {
return editorRef.current.execCommand({
name: declaration.name,
@@ -51,11 +56,11 @@ function editorCommandRuntime(declaration: CommandDeclaration, editorRef: any):
}
export default function useWindowCommandHandler(dependencies: HookDependencies) {
const { setShowLocalSearch, noteSearchBarRef, editorRef, titleInputRef } = dependencies;
const { setShowLocalSearch, noteSearchBarRef, editorRef, titleInputRef, setFormNote } = dependencies;
useEffect(() => {
for (const declaration of editorCommandDeclarations) {
CommandService.instance().registerRuntime(declaration.name, editorCommandRuntime(declaration, editorRef));
CommandService.instance().registerRuntime(declaration.name, editorCommandRuntime(declaration, editorRef, setFormNote));
}
const dependencies = {