added: option to display note tags in command palette

This commit is contained in:
quenousimporte 2023-11-06 09:59:01 +01:00
parent aa5a680b0f
commit 997ad9c5ed
1 changed files with 20 additions and 4 deletions

24
main.js
View File

@ -17,7 +17,8 @@ var defaultsettings =
colors: true, colors: true,
bulletrendering: "•", bulletrendering: "•",
password: "", password: "",
sync: false sync: false,
tagsinpalette: true
}; };
//builtin //builtin
@ -997,7 +998,10 @@ function gettags(note)
if (i > -1) if (i > -1)
{ {
var j = note.content.indexOf("\n", i); var j = note.content.indexOf("\n", i);
return note.content.substring(i + 6, j).split(",").map(t => t.toLowerCase().trim()); return note.content.substring(i + 6, j)
.split(",")
.map(t => t.toLowerCase().trim())
.filter(t => t.length);
} }
return []; return [];
} }
@ -1628,7 +1632,19 @@ function commandpalette()
.filter(c => !c.excludepalette) .filter(c => !c.excludepalette)
.map(c => c.hint) .map(c => c.hint)
.concat(snippets.map(s => "Insert snippet: " + s.hint)) .concat(snippets.map(s => "Insert snippet: " + s.hint))
.concat(list().map(t => "Open note: " + t)) .concat(localdata.map(n =>
{
var entry = "Open note: " + n.title;
if (settings.tagsinpalette)
{
var tags = gettags(n);
if (tags.length)
{
entry += " - tags: " + tags.join();
}
}
return entry;
}))
.concat(Object.keys(settings).map(s => "Edit setting: " + s))) .concat(Object.keys(settings).map(s => "Edit setting: " + s)))
.then(hint => .then(hint =>
{ {
@ -1647,7 +1663,7 @@ function commandpalette()
} }
else if (hint.startsWith("Open note: ")) else if (hint.startsWith("Open note: "))
{ {
loadnote(hint.replace("Open note: ", "")); loadnote(hint.replace("Open note: ", "").replace(/ - tags:.*/, ""));
} }
else if (hint.startsWith("Edit setting: ")) else if (hint.startsWith("Edit setting: "))
{ {