changed: scrollbar style

changed: caret color in theme
added: check box as list
added: plus plus theme
added: show info command (instead of word count)
fixed: theme selection on click
removed: confirmation before switching vault
changed: show temps info in search dialog
changed: download both vaults data in one json file
removed: light mode
added: vault in title bar
This commit is contained in:
quenousimporte 2023-01-24 22:17:48 +01:00
parent c8b9936ffc
commit 409dfdf4a8
2 changed files with 81 additions and 43 deletions

112
main.js
View File

@ -5,17 +5,17 @@ var defaultsettings =
fontsize: "90%", fontsize: "90%",
fontcolor: "black", fontcolor: "black",
lineheight: "130%", lineheight: "130%",
accentcolor: "#5AA7CE",
savedelay: 5000, savedelay: 5000,
foldmarkstart: 22232, foldmarkstart: 22232,
defaultpreviewinsplit: false, defaultpreviewinsplit: false,
enablefolding: false, enablefolding: false,
tagautocomplete: false, tagautocomplete: false
light: false
}; };
//builtin //builtin
var markerslist = ["* ", "- ", " * ", " - ", ">> ", "> ", "=> ", "— "]; var markerslist = ["* ", "- ", " * ", " - ", ">> ", "> ", "=> ", "— ", "[ ] "];
var sectionmarks = ["---", "### ", "## ", "# ", "```"]; var sectionmarks = ["---", "### ", "## ", "# ", "```"];
var codelanguages = ["xml", "js", "sql"]; var codelanguages = ["xml", "js", "sql"];
@ -40,7 +40,8 @@ var themes =
fontfamily: "'Inconsolata', 'Consolas', monospace", fontfamily: "'Inconsolata', 'Consolas', monospace",
fontsize: "90%", fontsize: "90%",
fontcolor: "black", fontcolor: "black",
lineheight: "130%" lineheight: "130%",
accentcolor: "#5AA7CE"
}, },
Notion: Notion:
{ {
@ -48,7 +49,8 @@ var themes =
fontfamily: "ui-sans-serif, -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, 'Apple Color Emoji', Arial, sans-serif, 'Segoe UI Emoji', 'Segoe UI Symbol'", fontfamily: "ui-sans-serif, -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, 'Apple Color Emoji', Arial, sans-serif, 'Segoe UI Emoji', 'Segoe UI Symbol'",
fontsize: "16px", fontsize: "16px",
fontcolor: "rgb(55,53,47)", fontcolor: "rgb(55,53,47)",
lineheight: "24px" lineheight: "24px",
accentcolor: "rgb(55,53,47)"
}, },
Monkey: Monkey:
{ {
@ -56,7 +58,8 @@ var themes =
fontfamily: "'Hack', 'Consolas', monospace", fontfamily: "'Hack', 'Consolas', monospace",
fontsize: "14px", fontsize: "14px",
fontcolor: "rgb(55,55,55)", fontcolor: "rgb(55,55,55)",
lineheight: "26px" lineheight: "24px",
accentcolor: "#5AA7CE"
}, },
Mariana: Mariana:
{ {
@ -64,7 +67,17 @@ var themes =
fontfamily: "'Consolas', monospace", fontfamily: "'Consolas', monospace",
fontsize: "15px", fontsize: "15px",
fontcolor: "rgb(216,222,233)", fontcolor: "rgb(216,222,233)",
lineheight: "100%" lineheight: "110%",
accentcolor: "rgb(249,174,88)"
},
"Plus plus":
{
bgcolor: "white",
fontfamily: "'Courier New'",
fontsize: "15px",
fontcolor: "black",
lineheight: "110%",
accentcolor: "rgb(128,0,255)"
} }
}; };
@ -218,11 +231,6 @@ var commands = [
savedonly: true, savedonly: true,
action: sortselection action: sortselection
}, },
{
hint: "Word count",
action: wordcount,
shortcut: "ctrl+w"
},
{ {
hint: "Settings", hint: "Settings",
savedonly: true, savedonly: true,
@ -260,7 +268,13 @@ var commands = [
hint: "Select theme", hint: "Select theme",
savedonly: true, savedonly: true,
action: selecttheme action: selecttheme
}]; },
{
hint: "Show note info",
action: showinfo,
shortcut: "ctrl+w"
}
];
var snippets = [ var snippets = [
{ {
@ -294,6 +308,19 @@ var snippets = [
cursor: 0 cursor: 0
}]; }];
function showinfo()
{
var tags = gettags(currentnote);
var info = [
"title: " + currentnote.title + "\n",
"vault: " + currentvault + "\n",
(tags ? "tags: " + tags + "\n" : ""),
"state: " + (saved ? "saved\n" : "not saved\n"),
"word count: " + getwords()];
showtemporaryinfo(info);
}
function loadtheme(theme) function loadtheme(theme)
{ {
for (var i in themes[theme]) for (var i in themes[theme])
@ -312,7 +339,11 @@ function savesettings()
function selecttheme() function selecttheme()
{ {
searchinlist(Object.keys(themes), loadtheme) searchinlist(Object.keys(themes), loadtheme)
.then(savesettings); .then(t =>
{
loadtheme(t);
savesettings();
});
} }
function addtagfilter() function addtagfilter()
@ -339,13 +370,9 @@ function addtagfilter()
function switchvault() function switchvault()
{ {
var other = othervault(); clearInterval(workerid);
if (confirm("Switch to " + other + "?")) window.localStorage.setItem("vault", othervault());
{ init();
clearInterval(workerid);
window.localStorage.setItem("vault", other);
init();
}
} }
function showinternallinks() function showinternallinks()
@ -471,14 +498,21 @@ function editsettings()
}); });
} }
function showtemporaryinfo(str) function showtemporaryinfo(data)
{ {
alert(str); if (typeof data == "string")
{
data = new Array(data);
}
searchinlist(data)
.then();
md.focus();
} }
function wordcount() function getwords()
{ {
showtemporaryinfo(getnotecontent().split(/\s+\b/).length + " words"); return getnotecontent().split(/\s+\b/).length;
} }
function issplit() function issplit()
@ -606,7 +640,12 @@ function downloadnotes()
function downloadlocal() function downloadlocal()
{ {
download(timestamp() + " " + currentvault + " notes.json", JSON.stringify(localdata)); var data =
{
local : JSON.parse(window.localStorage.getItem("local")),
remote : JSON.parse(window.localStorage.getItem("remote"))
};
download(timestamp() + " notes.json", JSON.stringify(data));
} }
function downloadnote() function downloadnote()
@ -684,7 +723,8 @@ function applystyle()
document.body.style.fontFamily = settings.fontfamily; document.body.style.fontFamily = settings.fontfamily;
document.body.style.fontSize = settings.fontsize; document.body.style.fontSize = settings.fontsize;
document.body.style.lineHeight = settings.lineheight; document.body.style.lineHeight = settings.lineheight;
document.body.style.color = settings.fontcolor; document.body.style.color = settings.fontcolor;
document.body.style.caretColor = settings.accentcolor;
} }
function loadsettings() function loadsettings()
@ -785,6 +825,8 @@ function init()
initsnippets(); initsnippets();
currenttag = "";
if (isremote()) if (isremote())
{ {
queryremote({action: "fetch"}) queryremote({action: "fetch"})
@ -1541,11 +1583,6 @@ function splitshortcut(s)
function mainkeydownhandler() function mainkeydownhandler()
{ {
if (settings.light)
{
return;
}
if (event.key == "Escape") if (event.key == "Escape")
{ {
if (!searchdialog.hidden) if (!searchdialog.hidden)
@ -1582,7 +1619,7 @@ function mainkeydownhandler()
event.preventDefault(); event.preventDefault();
if (command.savedonly && !saved) if (command.savedonly && !saved)
{ {
console.log("Data note saved, try again") console.log("Cannot perform '" + command.hint + "' because current note is not saved.");
} }
else if (command.action) else if (command.action)
{ {
@ -1594,11 +1631,12 @@ function mainkeydownhandler()
function setwindowtitle() function setwindowtitle()
{ {
document.title = title.value; document.title = currentvault + " -";
if (currenttag) if (currenttag)
{ {
document.title = "tag:" + currenttag + " - " + document.title; document.title += " tag:" + currenttag + " -";
} }
document.title += " " + currentnote.title;
} }
function ontitlechange() function ontitlechange()
@ -1677,7 +1715,7 @@ function editorkeydown()
insert("["); insert("[");
searchautocomplete(); searchautocomplete();
} }
else if (!settings.light && settings.tagautocomplete && event.key == " " && before(1) == "," && md.value.substring(0, getpos()).split("\n").pop().startsWith("tags: ")) else if (settings.tagautocomplete && event.key == " " && before(1) == "," && md.value.substring(0, getpos()).split("\n").pop().startsWith("tags: "))
{ {
event.preventDefault(); event.preventDefault();
// search in tags list // search in tags list
@ -1689,7 +1727,7 @@ function editorkeydown()
md.focus(); md.focus();
}) })
} }
else if (!settings.light) else
{ {
var snippet = snippets.find(s => before(s.command.length - 1) + event.key == s.command); var snippet = snippets.find(s => before(s.command.length - 1) + event.key == s.command);
if (snippet) if (snippet)

View File

@ -3,7 +3,6 @@
body { body {
margin-left: 7%; margin-left: 7%;
margin-right: 7%; margin-right: 7%;
caret-color: #5AA7CE;
} }
input { input {
@ -20,17 +19,17 @@ input {
:root :root
{ {
scrollbar-width: thin; scrollbar-width: thin;
scrollbar-color: RGBA(90, 167, 206, 0.5) lightgray; scrollbar-color: lightgray;
} }
body::-webkit-scrollbar { body::-webkit-scrollbar {
height: 5px; height: 7px;
width: 5px; width: 7px;
background-color: lightgray; background-color: darkgray;
} }
body::-webkit-scrollbar-thumb { body::-webkit-scrollbar-thumb {
background-color: RGBA(90, 167, 206, 0.5); background-color: lightgray;
border-radius: 10px; border-radius: 10px;
} }
@ -96,6 +95,7 @@ body::-webkit-scrollbar-thumb {
background-color: lightgray; background-color: lightgray;
opacity: 1; opacity: 1;
width: 90%; width: 90%;
color: black;
} }
/* authent */ /* authent */