Mobile: Fixes #5949: Scroll selection into view in beta editor when window resizes (#6610)

pull/6618/head^2
Henry Heino 2022-06-26 10:21:38 -07:00 committed by GitHub
parent 8f3fd0bf8b
commit c7e3245008
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -26,8 +26,9 @@ interface CodeMirrorResult {
editor: EditorView;
undo: Function;
redo: Function;
select: (anchor: number, head: number)=> void;
insertText: (text: string)=> void;
select(anchor: number, head: number): void;
scrollSelectionIntoView(): void;
insertText(text: string): void;
}
function postMessage(name: string, data: any) {
@ -231,6 +232,11 @@ export function initCodeMirror(parentElement: any, initialText: string, theme: a
scrollIntoView: true,
}));
},
scrollSelectionIntoView: () => {
editor.dispatch(editor.state.update({
scrollIntoView: true,
}));
},
insertText: (text: string) => {
editor.dispatch(editor.state.replaceSelection(text));
},

View File

@ -266,6 +266,11 @@ function NoteEditor(props: Props, ref: any) {
cm = codeMirrorBundle.initCodeMirror(parentElement, initialText, theme);
${setInitialSelectionJS}
// Fixes https://github.com/laurent22/joplin/issues/5949
window.onresize = () => {
cm.scrollSelectionIntoView();
};
} catch (e) {
window.ReactNativeWebView.postMessage("error:" + e.message + ": " + JSON.stringify(e))
} finally {