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