You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-26 22:41:17 +02:00
Mobile: Improve inline search performance in large documents (#13259)
This commit is contained in:
@@ -90,6 +90,8 @@ function editorTheme(themeId: number) {
|
||||
};
|
||||
}
|
||||
|
||||
const noteEditorSearchChangeSource = 'joplin.noteEditor.setSearchState';
|
||||
|
||||
type OnSetVisibleCallback = (visible: boolean)=> void;
|
||||
type OnSearchStateChangeCallback = (state: SearchState)=> void;
|
||||
const useEditorControl = (
|
||||
@@ -104,7 +106,7 @@ const useEditorControl = (
|
||||
};
|
||||
|
||||
const setSearchStateCallback = (state: SearchState) => {
|
||||
editorRef.current.setSearchState(state);
|
||||
editorRef.current.setSearchState(state, noteEditorSearchChangeSource);
|
||||
setSearchState(state);
|
||||
};
|
||||
|
||||
@@ -310,15 +312,26 @@ function NoteEditor(props: Props) {
|
||||
case EditorEventType.FollowLink:
|
||||
void CommandService.instance().execute('openItem', event.link);
|
||||
break;
|
||||
case EditorEventType.UpdateSearchDialog:
|
||||
setSearchState(event.searchState);
|
||||
case EditorEventType.UpdateSearchDialog: {
|
||||
const hasExternalChange = (
|
||||
event.changeSources.length !== 1
|
||||
|| event.changeSources[0] !== noteEditorSearchChangeSource
|
||||
);
|
||||
|
||||
if (event.searchState.dialogVisible) {
|
||||
editorControl.searchControl.showSearch();
|
||||
} else {
|
||||
editorControl.searchControl.hideSearch();
|
||||
// If the change to the search was done by this editor, it was already applied to the
|
||||
// search state. Skipping the update in this case also helps avoid overwriting the
|
||||
// search state with an older value.
|
||||
if (hasExternalChange) {
|
||||
setSearchState(event.searchState);
|
||||
|
||||
if (event.searchState.dialogVisible) {
|
||||
editorControl.searchControl.showSearch();
|
||||
} else {
|
||||
editorControl.searchControl.hideSearch();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case EditorEventType.Remove:
|
||||
case EditorEventType.Scroll:
|
||||
// Not handled
|
||||
|
||||
@@ -158,8 +158,7 @@ export const SearchPanel = (props: SearchPanelProps) => {
|
||||
const state = props.searchState;
|
||||
const control = props.searchControl;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
||||
const updateSearchState = (changedData: any) => {
|
||||
const updateSearchState = (changedData: Partial<SearchState>) => {
|
||||
const newState = { ...state, ...changedData };
|
||||
control.setSearchState(newState);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user