mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-15 09:04:04 +02:00
3a57cfea02
- Commands "enabled" state is now expressed using a "when-clause" like in VSCode - A command palette has been added to the Tools menu
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import { CommandRuntime, CommandDeclaration, CommandContext } from 'lib/services/CommandService';
|
|
const BaseModel = require('lib/BaseModel');
|
|
const uuid = require('lib/uuid').default;
|
|
|
|
export const declaration:CommandDeclaration = {
|
|
name: 'search',
|
|
iconName: 'icon-search',
|
|
};
|
|
|
|
export const runtime = (comp:any):CommandRuntime => {
|
|
return {
|
|
execute: async (_context:CommandContext, query:string) => {
|
|
if (!comp.searchId_) comp.searchId_ = uuid.create();
|
|
|
|
comp.props.dispatch({
|
|
type: 'SEARCH_UPDATE',
|
|
search: {
|
|
id: comp.searchId_,
|
|
title: query,
|
|
query_pattern: query,
|
|
query_folder_id: null,
|
|
type_: BaseModel.TYPE_SEARCH,
|
|
},
|
|
});
|
|
|
|
if (query) {
|
|
comp.props.dispatch({
|
|
type: 'SEARCH_SELECT',
|
|
id: comp.searchId_,
|
|
});
|
|
} else {
|
|
// Note: Normally there's no need to do anything when the search query
|
|
// is cleared as the reducer should handle all state changes.
|
|
// https://github.com/laurent22/joplin/issues/3748
|
|
|
|
// const note = await Note.load(comp.props.selectedNoteId);
|
|
// if (note) {
|
|
// comp.props.dispatch({
|
|
// type: 'FOLDER_AND_NOTE_SELECT',
|
|
// folderId: note.parent_id,
|
|
// noteId: note.id,
|
|
// });
|
|
// }
|
|
}
|
|
},
|
|
};
|
|
};
|