removed: toggle md header feature

changed: info order
This commit is contained in:
quenousimporte 2023-07-17 11:25:08 +02:00
parent 5617238cbb
commit 18413883a5
1 changed files with 12 additions and 58 deletions

70
main.js
View File

@ -14,7 +14,6 @@ var defaultsettings =
titleinaccentcolor: false, titleinaccentcolor: false,
enablenetwork: false, enablenetwork: false,
titlebydefault: false, titlebydefault: false,
hideheaderbydefault: true,
linksinnewtab: true linksinnewtab: true
}; };
@ -25,7 +24,6 @@ var codelanguages = ["xml", "js", "sql"];
// globals // globals
var currentnote = null; var currentnote = null;
var currentheader = "";
var fileindex = 0; var fileindex = 0;
var workerid = null; var workerid = null;
var backup = ""; var backup = "";
@ -209,12 +207,6 @@ var commands = [
hint: "Restore note", hint: "Restore note",
action: restore action: restore
}, },
{
shortcut: "ctrl+h",
hint: "Toggle markdown header",
action: toggleheader,
allowunsaved: true
},
{ {
shortcut: "F1", shortcut: "F1",
hint: "Show help", hint: "Show help",
@ -521,10 +513,10 @@ function showinfo()
var tags = gettags(currentnote); var tags = gettags(currentnote);
showtemporaryinfo( showtemporaryinfo(
[ [
"vault: " + currentvault,
"saved: " + saved, "saved: " + saved,
"title: " + currentnote.title, "title: " + currentnote.title,
"cursor position: " + md.selectionStart + " (" + (100 * md.selectionStart / md.value.length).toFixed(2) + "%)", "cursor position: " + md.selectionStart + " (" + (100 * md.selectionStart / md.value.length).toFixed(2) + "%)",
"vault: " + currentvault,
(tags ? "tags: " + tags : ""), (tags ? "tags: " + tags : ""),
"spell check: " + (md.spellcheck ? "en" : "dis") + "abled", "spell check: " + (md.spellcheck ? "en" : "dis") + "abled",
"notes count: " + localdata.length, "notes count: " + localdata.length,
@ -753,7 +745,7 @@ function showoutline()
{ {
var outline = {}; var outline = {};
var pos = 0; var pos = 0;
geteditorcontentwithheader().split("\n").forEach((line, index, lines) => md.value.split("\n").forEach((line, index, lines) =>
{ {
pos += line.length + 1; pos += line.length + 1;
if (line.startsWith("#")) if (line.startsWith("#"))
@ -897,7 +889,7 @@ function showtemporaryinfo(info)
function getwords() function getwords()
{ {
return geteditorcontentwithheader().split(/\s+\b/).length; return md.value.split(/\s+\b/).length;
} }
function issplit() function issplit()
@ -973,7 +965,7 @@ function share()
{ {
navigator.share( navigator.share(
{ {
text: geteditorcontentwithheader(), text: md.value,
title: currentnote.title title: currentnote.title
}); });
} }
@ -983,7 +975,7 @@ function sharehtml()
{ {
if (navigator.share) if (navigator.share)
{ {
var file = new File(['<html><body>' + md2html(geteditorcontentwithheader()) + '</body></html>'], var file = new File(['<html><body>' + md2html(md.value) + '</body></html>'],
currentnote.title + ".html", currentnote.title + ".html",
{ {
type: "text/html", type: "text/html",
@ -1072,7 +1064,7 @@ function downloadnotewithsubs()
function downloadnote() function downloadnote()
{ {
download(currentnote.title + ".md", geteditorcontentwithheader()); download(currentnote.title + ".md", md.value);
} }
function remotecallfailed(error) function remotecallfailed(error)
@ -1532,7 +1524,7 @@ function getlinesrange()
function sortselection() function sortselection()
{ {
var content = geteditorcontentwithheader(); var content = md.value;
var range = {start: 0, end: content.length}; var range = {start: 0, end: content.length};
if (md.selectionStart != md.selectionEnd) if (md.selectionStart != md.selectionEnd)
{ {
@ -1557,11 +1549,6 @@ function seteditorcontent(content)
md.value = content; md.value = content;
} }
function geteditorcontentwithheader()
{
return currentheader + md.value;
}
function ontopbarclick() function ontopbarclick()
{ {
if (title.hidden) if (title.hidden)
@ -1908,7 +1895,7 @@ async function save()
return; return;
} }
var content = geteditorcontentwithheader(); var content = md.value;
if ((content == "" && backup != "") || content == "null" || content == "undefined") if ((content == "" && backup != "") || content == "null" || content == "undefined")
{ {
showtemporaryinfo("Invalid content '" + content + "', file '" + currentnote.title + "' not saved"); showtemporaryinfo("Invalid content '" + content + "', file '" + currentnote.title + "' not saved");
@ -1948,7 +1935,7 @@ async function save()
.finally(() => .finally(() =>
{ {
pending = false; pending = false;
if (content != geteditorcontentwithheader()) if (content != md.value)
{ {
console.log("but content changed: will save again"); console.log("but content changed: will save again");
datachanged(); datachanged();
@ -2136,33 +2123,6 @@ function restore()
} }
} }
function toggleheader()
{
if (preview.hidden)
{
if (md.value.startsWith("---\n"))
{
var idx = md.value.indexOf("---", 3);
var header = md.value.substring(0, idx + 4);
currentheader = header;
md.value = md.value.substring(idx + 4);
}
else if (currentheader)
{
md.value = currentheader + md.value;
currentheader = "";
}
else
{
var headers = "---\ndate: " + (new Date).toISOString().substring(0, 10) + "\ntags: \n---\n\n";
md.value = headers + md.value;
setpos(27);
}
resize();
}
}
function splitshortcut(s) function splitshortcut(s)
{ {
var r = {}; var r = {};
@ -2394,7 +2354,7 @@ function insertautocomplete(selectednote)
function togglepreview() function togglepreview()
{ {
preview.innerHTML = md2html(geteditorcontentwithheader()); preview.innerHTML = md2html(md.value);
md.hidden = !md.hidden; md.hidden = !md.hidden;
preview.hidden = !preview.hidden; preview.hidden = !preview.hidden;
@ -2420,7 +2380,7 @@ function withsubs()
var tempnote = var tempnote =
{ {
title: currentnote.title + " (with subnotes)", title: currentnote.title + " (with subnotes)",
content: geteditorcontentwithheader() content: md.value
}; };
var kids = children(tempnote); var kids = children(tempnote);
@ -2469,7 +2429,7 @@ function bindfile(note)
setwindowtitle(); setwindowtitle();
seteditorcontent(note.content || ""); seteditorcontent(note.content || "");
preview.innerHTML = md2html(geteditorcontentwithheader()); preview.innerHTML = md2html(md.value);
if (changed) if (changed)
{ {
@ -2483,12 +2443,6 @@ function bindfile(note)
md.focus(); md.focus();
} }
currentheader = "";
if (settings.hideheaderbydefault && md.value.startsWith("---\n"))
{
toggleheader();
}
setpos(note.pos || 0); setpos(note.pos || 0);
} }