2020-11-07 17:59:37 +02:00
|
|
|
import { CommandRuntime, CommandDeclaration } from '@joplin/lib/services/CommandService';
|
|
|
|
import { _ } from '@joplin/lib/locale';
|
2024-04-01 16:34:22 +02:00
|
|
|
import { focus } from '@joplin/lib/utils/focusHandler';
|
2020-07-03 23:32:39 +02:00
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
export const declaration: CommandDeclaration = {
|
2020-07-03 23:32:39 +02:00
|
|
|
name: 'showLocalSearch',
|
|
|
|
label: () => _('Search in current note'),
|
|
|
|
};
|
|
|
|
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-12 21:13:28 +02:00
|
|
|
export const runtime = (comp: any): CommandRuntime => {
|
2020-07-03 23:32:39 +02:00
|
|
|
return {
|
|
|
|
execute: async () => {
|
2024-03-14 21:04:32 +02:00
|
|
|
if (comp.editorRef.current && await comp.editorRef.current.supportsCommand('search')) {
|
2020-07-03 23:32:39 +02:00
|
|
|
comp.editorRef.current.execCommand({ name: 'search' });
|
|
|
|
} else {
|
2022-12-31 01:54:04 +02:00
|
|
|
if (comp.noteSearchBarRef.current) {
|
2024-04-01 16:34:22 +02:00
|
|
|
focus('showLocalSearch', comp.noteSearchBarRef.current);
|
2022-12-31 01:54:04 +02:00
|
|
|
} else {
|
|
|
|
comp.setShowLocalSearch(true);
|
|
|
|
}
|
2020-07-03 23:32:39 +02:00
|
|
|
}
|
|
|
|
},
|
2020-10-18 22:52:10 +02:00
|
|
|
enabledCondition: 'oneNoteSelected',
|
2020-07-03 23:32:39 +02:00
|
|
|
};
|
|
|
|
};
|