Skip to content

Commit

Permalink
Mobile: Fixes #10130: Improve note editor performance when quickly en…
Browse files Browse the repository at this point in the history
…tering text (#10134)
  • Loading branch information
personalizedrefrigerator authored Mar 20, 2024
1 parent e92f89d commit d260d0e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
23 changes: 14 additions & 9 deletions packages/app-mobile/components/screens/Note.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import { PluginStates } from '@joplin/lib/services/plugins/reducer';
import pickDocument from '../../utils/pickDocument';
import { ContainerType } from '@joplin/lib/services/plugins/WebviewController';
import PluginPanelViewer from '../../plugins/PluginRunner/dialogs/PluginPanelViewer';
import debounce from '../../utils/debounce';
const urlUtils = require('@joplin/lib/urlUtils');

const emptyArray: any[] = [];
Expand Down Expand Up @@ -319,7 +320,6 @@ class NoteScreenComponent extends BaseScreenComponent<Props, State> implements B
this.screenHeader_redoButtonPress = this.screenHeader_redoButtonPress.bind(this);
this.onBodyViewerLoadEnd = this.onBodyViewerLoadEnd.bind(this);
this.onBodyViewerCheckboxChange = this.onBodyViewerCheckboxChange.bind(this);
this.onBodyChange = this.onBodyChange.bind(this);
this.onUndoRedoDepthChange = this.onUndoRedoDepthChange.bind(this);
this.voiceTypingDialog_onText = this.voiceTypingDialog_onText.bind(this);
this.voiceTypingDialog_onDismiss = this.voiceTypingDialog_onDismiss.bind(this);
Expand All @@ -329,10 +329,6 @@ class NoteScreenComponent extends BaseScreenComponent<Props, State> implements B
return this.props.useEditorBeta;
}

private onBodyChange(event: EditorChangeEvent) {
shared.noteComponent_change(this, 'body', event.value);
this.scheduleSave();
}

private onUndoRedoDepthChange(event: UndoRedoDepthChangeEvent) {
if (this.useEditorBeta()) {
Expand Down Expand Up @@ -594,7 +590,7 @@ class NoteScreenComponent extends BaseScreenComponent<Props, State> implements B
this.scheduleSave();
}

private body_changeText(text: string) {
private onPlainEditorTextChange = (text: string) => {
if (!this.undoRedoService_.canUndo) {
this.undoRedoService_.push(this.undoState());
} else {
Expand All @@ -603,7 +599,16 @@ class NoteScreenComponent extends BaseScreenComponent<Props, State> implements B

shared.noteComponent_change(this, 'body', text);
this.scheduleSave();
}
};

// Avoid saving immediately -- the NoteEditor's content isn't controlled by its props
// and updating this.state.note immediately causes slow rerenders.
//
// See https://github.com/laurent22/joplin/issues/10130
private onMarkdownEditorTextChange = debounce((event: EditorChangeEvent) => {
shared.noteComponent_change(this, 'body', event.value);
this.scheduleSave();
}, 100);

private onPlainEditorSelectionChange = (event: NativeSyntheticEvent<any>) => {
this.selection = event.nativeEvent.selection;
Expand Down Expand Up @@ -1502,7 +1507,7 @@ class NoteScreenComponent extends BaseScreenComponent<Props, State> implements B
ref="noteBodyTextField"
multiline={true}
value={note.body}
onChangeText={(text: string) => this.body_changeText(text)}
onChangeText={this.onPlainEditorTextChange}
onSelectionChange={this.onPlainEditorSelectionChange}
blurOnSubmit={false}
selectionColor={theme.textSelectionColor}
Expand All @@ -1524,7 +1529,7 @@ class NoteScreenComponent extends BaseScreenComponent<Props, State> implements B
themeId={this.props.themeId}
initialText={note.body}
initialSelection={this.selection}
onChange={this.onBodyChange}
onChange={this.onMarkdownEditorTextChange}
onSelectionChange={this.onMarkdownEditorSelectionChange}
onUndoRedoDepthChange={this.onUndoRedoDepthChange}
onAttach={() => this.showAttachMenu()}
Expand Down
1 change: 0 additions & 1 deletion packages/app-mobile/utils/shim-init-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const injectedJs = {
codeMirrorBundle: require('../lib/rnInjectedJs/codeMirrorBundle.bundle'),
svgEditorBundle: require('../lib/rnInjectedJs/svgEditorBundle.bundle'),
pluginBackgroundPage: require('../lib/rnInjectedJs/pluginBackgroundPage.bundle'),
noteBodyViewerBundle: require('../lib/rnInjectedJs/noteBodyViewerBundle.bundle'),

This comment has been minimized.

Copy link
@personalizedrefrigerator

personalizedrefrigerator Mar 20, 2024

Author Collaborator

See #10164

};

function shimInit() {
Expand Down

0 comments on commit d260d0e

Please sign in to comment.