From f0f659031218525d4ee862b1917b612c06ebb52e Mon Sep 17 00:00:00 2001 From: pedr Date: Sat, 2 Mar 2024 12:53:46 -0300 Subject: [PATCH] Desktop: Fixes #9919: Command palette not showing note title (#9961) --- packages/app-desktop/plugins/GotoAnything.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/app-desktop/plugins/GotoAnything.tsx b/packages/app-desktop/plugins/GotoAnything.tsx index 066b184bd..e828d0059 100644 --- a/packages/app-desktop/plugins/GotoAnything.tsx +++ b/packages/app-desktop/plugins/GotoAnything.tsx @@ -340,6 +340,8 @@ class Dialog extends React.PureComponent { } else { // Note TITLE or BODY listType = BaseModel.TYPE_NOTE; searchQuery = gotoAnythingStyleQuery(this.state.query); + // SearchEngine returns the title normalized, that is why we need to + // override this field below with the original title results = (await SearchEngine.instance().search(searchQuery)) as any[]; resultsInBody = !!results.find((row: any) => row.fields.includes('body')); @@ -348,10 +350,12 @@ class Dialog extends React.PureComponent { const resources = await Resource.resourceOcrTextsByIds(resourceIds); if (!resultsInBody || this.state.query.length <= 1) { + const notes = await Note.byIds(results.map((result: any) => result.id), { fields: ['id', 'title'] }); for (let i = 0; i < results.length; i++) { const row = results[i]; const path = Folder.folderPathString(this.props.folders, row.parent_id); - results[i] = { ...row, path: path }; + const originalNote = notes.find(note => note.id === row.id); + results[i] = { ...row, path: path, title: originalNote.title }; } } else { const limit = 20; @@ -364,13 +368,14 @@ class Dialog extends React.PureComponent { results = results.filter((row: any) => !row.is_todo || !row.todo_completed); } - const notes = await Note.byIds(results.map((result: any) => result.id).slice(0, limit), { fields: ['id', 'body', 'markup_language', 'is_todo', 'todo_completed'] }); + const notes = await Note.byIds(results.map((result: any) => result.id).slice(0, limit), { fields: ['id', 'body', 'markup_language', 'is_todo', 'todo_completed', 'title'] }); // Can't make any sense of this code so... - const notesById = notes.reduce((obj, { id, body, markup_language }) => ((obj[[id] as any] = { id, body, markup_language }), obj), {}); + const notesById = notes.reduce((obj, { id, body, markup_language, title }) => ((obj[[id] as any] = { id, body, markup_language, title }), obj), {}); // Filter out search results that are associated with non-existing notes. // https://github.com/laurent22/joplin/issues/5417 - results = results.filter(r => !!notesById[r.id]); + results = results.filter(r => !!notesById[r.id]) + .map(r => ({ ...r, title: notesById[r.id].title })); for (let i = 0; i < results.length; i++) { const row = results[i];