From d91158e7521003a3797bea6dc3c5d06970797938 Mon Sep 17 00:00:00 2001 From: quenousimporte <76260127+quenousimporte@users.noreply.github.com> Date: Wed, 1 Feb 2023 13:54:49 +0100 Subject: [PATCH] added: create subnote from section (if folding disabled) --- main.js | 96 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 60 insertions(+), 36 deletions(-) diff --git a/main.js b/main.js index 35dc07e..ff275ae 100644 --- a/main.js +++ b/main.js @@ -187,7 +187,7 @@ var commands = [ { shortcut: "ctrl+d", hint: "Delete note", - action: deletenote + action: deletecurrentnote }, { hint: "Restore note", @@ -221,19 +221,6 @@ var commands = [ action: unfoldall, allowunsaved: true }, -{ - hint: "Download note", - action: downloadnote -}, -{ - hint: "Download note with subnotes", - action: downloadnotewithsubs -}, -{ - hint: "Download vault", - action: downloadvault, - shortcut: "ctrl+shift+S" -}, { hint: "Search tags", action: searchtags, @@ -314,12 +301,25 @@ var commands = [ action: createsubnote }, { - hint: "Include subnote", + hint: "Merge subnote", action: includesub }, { hint: "Comment selection", action: comment +}, +{ + hint: "Download note", + action: downloadnote +}, +{ + hint: "Download note with merged subnotes", + action: downloadnotewithsubs +}, +{ + hint: "Download vault", + action: downloadvault, + shortcut: "ctrl+shift+S" }]; var snippets = [ @@ -359,16 +359,28 @@ function getnote(title) return localdata.find(note => note.title == title); } -function createsubnote() +function createsubnote(suggestedtitle) { + var name = []; + if (suggestedtitle) + { + name.push(suggestedtitle); + } var range = getlinesrange(); var content = md.value.substring(range.start, range.end); - searchinlist([], null, "Title...") + filter.placeholder = "Subnote title..."; + searchinlist(name) .then(title => { - if (getnote(title)) + if (!title) + { + showtemporaryinfo("No title provided"); + setpos(md.selectionStart); + } + else if (getnote(title)) { showtemporaryinfo("'" + title + "' already exists"); + setpos(md.selectionStart); } else { @@ -403,11 +415,17 @@ function includesub() var title = linkatpos(); if (confirm("Replace [[" + title + "]] by its content?")) { + var subnote = getnote(title); md.value = md.value.substring(0, range.start) - + getnote(title).content + + subnote.content + md.value.substring(range.end); + if (confirm("Delete '" + title + "'?")) + { + deletenote(subnote); + } + datachanged(); } } @@ -834,7 +852,7 @@ function downloadnotewithsubs() var tempnote = { - title: currentnote.title + " (with sub notes)", + title: currentnote.title + " (with subnotes)", content: getnotecontent() }; @@ -1215,12 +1233,6 @@ function unfoldall() function checkfolding() { - if (!settings.enablefolding) - { - console.log("folding is disabled."); - return; - } - var range = getlinesrange(); var line = md.value.substring(range.start, range.end); var sectionmark = sectionmarks.find(m => line.startsWith(m)); @@ -1256,7 +1268,15 @@ function checkfolding() } md.setSelectionRange(range.start, sectionend); - fold(); + + if (settings.enablefolding) + { + fold(); + } + else + { + createsubnote(currentnote.title + " -" + line.replace(/#/g, "")); + } } } else if (isfold(line)) @@ -1775,18 +1795,22 @@ function rename(newname) return ""; } -function deletenote() +function deletenote(note) +{ + var trash = JSON.parse(window.localStorage.getItem("trash")) || []; + trash.push(note); + window.localStorage.setItem("trash", JSON.stringify(trash)); + + localdata = localdata.filter(n => n != note); + + renamereferences(note.title + " (deleted)"); +} + +function deletecurrentnote() { if (confirm('delete "' + currentnote.title + '"?')) { - var trash = JSON.parse(window.localStorage.getItem("trash")) || []; - trash.push(currentnote); - window.localStorage.setItem("trash", JSON.stringify(trash)); - - localdata = localdata.filter(n => n != currentnote); - - renamereferences(currentnote.title + " (deleted)"); - + deletenote(currentnote); loadlast(); datachanged(); }