From fd390dff6b602bff7bf91b5b23bebe0d6740cd4b Mon Sep 17 00:00:00 2001 From: Neeraj Kashyap Date: Sun, 14 Mar 2021 08:06:38 -0700 Subject: [PATCH] Desktop: Resolves #2810: Ctrl+Shift+B to viewer when editor invisible (#4537) --- .../gui/NoteEditor/NoteBody/CodeMirror/CodeMirror.tsx | 8 ++++++-- packages/app-desktop/gui/NoteTextViewer.tsx | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/CodeMirror.tsx b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/CodeMirror.tsx index 9a469b5802..22be2c87a8 100644 --- a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/CodeMirror.tsx +++ b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/CodeMirror.tsx @@ -141,7 +141,11 @@ function CodeMirror(props: NoteBodyEditorProps, ref: any) { reg.logger().warn('CodeMirror: unsupported drop item: ', cmd); } } else if (cmd.name === 'editor.focus') { - editorRef.current.focus(); + if (props.visiblePanes.indexOf('editor') >= 0) { + editorRef.current.focus(); + } else { + webviewRef.current.wrappedInstance.focus(); + } } else { commandProcessed = false; } @@ -242,7 +246,7 @@ function CodeMirror(props: NoteBodyEditorProps, ref: any) { return commandOutput; }, }; - }, [props.content, addListItem, wrapSelectionWithStrings, setEditorPercentScroll, setViewerPercentScroll, resetScroll, renderedBody]); + }, [props.content, props.visiblePanes, addListItem, wrapSelectionWithStrings, setEditorPercentScroll, setViewerPercentScroll, resetScroll, renderedBody]); const onEditorPaste = useCallback(async (event: any = null) => { const resourceMds = await handlePasteEvent(event); diff --git a/packages/app-desktop/gui/NoteTextViewer.tsx b/packages/app-desktop/gui/NoteTextViewer.tsx index 57dbaa5951..8d9413e012 100644 --- a/packages/app-desktop/gui/NoteTextViewer.tsx +++ b/packages/app-desktop/gui/NoteTextViewer.tsx @@ -114,6 +114,12 @@ class NoteTextViewerComponent extends React.Component { this.domReady_ = false; } + focus() { + if (this.webviewRef_.current) { + this.webviewRef_.current.focus(); + } + } + tryInit() { if (!this.initialized_ && this.webviewRef_.current) { this.initWebview();