changed: tag filter now persistent

This commit is contained in:
quenousimporte 2023-11-07 15:28:32 +01:00
parent d805864972
commit 78afdb4628
1 changed files with 12 additions and 12 deletions

24
main.js
View File

@ -18,7 +18,8 @@ var defaultsettings =
bulletrendering: "•", bulletrendering: "•",
password: "", password: "",
sync: false, sync: false,
tagsinlists: true tagsinlists: true,
tagfilter: ""
}; };
//builtin //builtin
@ -36,7 +37,6 @@ var lastsaved = "";
var pending = false; var pending = false;
var settings = null; var settings = null;
var tags = null; var tags = null;
var currenttag = "";
var stat = var stat =
{ {
@ -501,7 +501,7 @@ function showinfo()
"word count: " + getwords(), "word count: " + getwords(),
"cursor position: " + md.selectionStart + " (" + pospercent() + "%)", "cursor position: " + md.selectionStart + " (" + pospercent() + "%)",
(tags ? "tags: " + tags : ""), (tags ? "tags: " + tags : ""),
"current filter: " + currenttag || "", "current filter: " + settings.tagfilter || "",
"current note start: " + stat.cur.t, "current note start: " + stat.cur.t,
"current note queries: " + stat.cur.q, "current note queries: " + stat.cur.q,
"current note data sent: " + formatsize(stat.cur.d), "current note data sent: " + formatsize(stat.cur.d),
@ -523,19 +523,21 @@ function addtagfilter()
{ {
var command = commands.find(c => c.action == addtagfilter); var command = commands.find(c => c.action == addtagfilter);
if (!currenttag) if (!settings.tagfilter)
{ {
tagslist() tagslist()
.then(t => .then(t =>
{ {
currenttag = t; settings.tagfilter = t;
command.hint = "Remove tag filter '" + currenttag + "'"; savesettings();
command.hint = "Remove tag filter '" + settings.tagfilter + "'";
setwindowtitle(); setwindowtitle();
}); });
} }
else else
{ {
currenttag = ""; settings.tagfilter = "";
savesettings();
command.hint = "Add tag filter"; command.hint = "Add tag filter";
setwindowtitle(); setwindowtitle();
} }
@ -1294,8 +1296,6 @@ function init()
initsnippets(); initsnippets();
currenttag = "";
if (isremote()) if (isremote())
{ {
if (localStorage.getItem("pgpkeys") && localStorage.getItem("pgpkeys").startsWith("-----BEGIN PGP PUBLIC KEY BLOCK-----")) if (localStorage.getItem("pgpkeys") && localStorage.getItem("pgpkeys").startsWith("-----BEGIN PGP PUBLIC KEY BLOCK-----"))
@ -1551,7 +1551,7 @@ function md2html(content)
function list() function list()
{ {
return localdata return localdata
.filter(n => currenttag == "" || gettags(n).includes(currenttag)) .filter(n => settings.tagfilter == "" || gettags(n).includes(settings.tagfilter))
.map(n => n.title); .map(n => n.title);
} }
@ -2576,7 +2576,7 @@ function mainkeydownhandler()
function setwindowtitle() function setwindowtitle()
{ {
document.title = (currenttag ? "🏷" + currenttag + " | " : "") + currentnote.title; document.title = (settings.tagfilter ? "🏷" + settings.tagfilter + " | " : "") + currentnote.title;
} }
function ontitlechange() function ontitlechange()
@ -2822,7 +2822,7 @@ function defaultheaders(title, tags = "")
"---", "---",
"title: " + title, "title: " + title,
"date: " + timestamp().substr(0,10), "date: " + timestamp().substr(0,10),
"tags: " + (tags || currenttag || ""), "tags: " + (tags || settings.tagfilter || ""),
"---", "---",
"",""].join("\n"); "",""].join("\n");
} }