Skip to content

Commit

Permalink
Mobile: Fixes #10637: Fix refocusing the note editor (#10644)
Browse files Browse the repository at this point in the history
  • Loading branch information
personalizedrefrigerator authored Jun 21, 2024
1 parent 4115e20 commit 77e7411
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 10 additions & 0 deletions packages/app-mobile/components/NoteEditor/CodeMirror/CodeMirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import createEditor from '@joplin/editor/CodeMirror/createEditor';
import CodeMirrorControl from '@joplin/editor/CodeMirror/CodeMirrorControl';
import WebViewToRNMessenger from '../../../utils/ipc/WebViewToRNMessenger';
import { WebViewToEditorApi } from '../types';
import { focus } from '@joplin/lib/utils/focusHandler';

export const initCodeMirror = (
parentElement: HTMLElement,
Expand Down Expand Up @@ -47,6 +48,15 @@ export const initCodeMirror = (
}
});

// Note: Just adding an onclick listener seems sufficient to focus the editor when its background
// is tapped.
parentElement.addEventListener('click', (event) => {
const activeElement = document.querySelector(':focus');
if (!parentElement.contains(activeElement) && event.target === parentElement) {
focus('initial editor focus', control);
}
});

messenger.setLocalInterface(control);
return control;
};
4 changes: 0 additions & 4 deletions packages/app-mobile/components/NoteEditor/NoteEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ function useHtml(initialCss: string): string {
scrolling. */
.cm-scroller {
overflow: none;
/* Ensure that the editor can be focused by clicking on the lower half of the screen.
Don't use 100vh to prevent a scrollbar being present for empty notes. */
min-height: 80vh;
}
</style>
<style class=${JSON.stringify(themeStyleSheetClassName)}>
Expand Down

0 comments on commit 77e7411

Please sign in to comment.