added: create subnote from section (if folding disabled)
This commit is contained in:
parent
712694bd28
commit
d91158e752
92
main.js
92
main.js
|
@ -187,7 +187,7 @@ var commands = [
|
||||||
{
|
{
|
||||||
shortcut: "ctrl+d",
|
shortcut: "ctrl+d",
|
||||||
hint: "Delete note",
|
hint: "Delete note",
|
||||||
action: deletenote
|
action: deletecurrentnote
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
hint: "Restore note",
|
hint: "Restore note",
|
||||||
|
@ -221,19 +221,6 @@ var commands = [
|
||||||
action: unfoldall,
|
action: unfoldall,
|
||||||
allowunsaved: true
|
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",
|
hint: "Search tags",
|
||||||
action: searchtags,
|
action: searchtags,
|
||||||
|
@ -314,12 +301,25 @@ var commands = [
|
||||||
action: createsubnote
|
action: createsubnote
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
hint: "Include subnote",
|
hint: "Merge subnote",
|
||||||
action: includesub
|
action: includesub
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
hint: "Comment selection",
|
hint: "Comment selection",
|
||||||
action: comment
|
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 = [
|
var snippets = [
|
||||||
|
@ -359,16 +359,28 @@ function getnote(title)
|
||||||
return localdata.find(note => note.title == title);
|
return localdata.find(note => note.title == title);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createsubnote()
|
function createsubnote(suggestedtitle)
|
||||||
{
|
{
|
||||||
|
var name = [];
|
||||||
|
if (suggestedtitle)
|
||||||
|
{
|
||||||
|
name.push(suggestedtitle);
|
||||||
|
}
|
||||||
var range = getlinesrange();
|
var range = getlinesrange();
|
||||||
var content = md.value.substring(range.start, range.end);
|
var content = md.value.substring(range.start, range.end);
|
||||||
searchinlist([], null, "Title...")
|
filter.placeholder = "Subnote title...";
|
||||||
|
searchinlist(name)
|
||||||
.then(title =>
|
.then(title =>
|
||||||
{
|
{
|
||||||
if (getnote(title))
|
if (!title)
|
||||||
|
{
|
||||||
|
showtemporaryinfo("No title provided");
|
||||||
|
setpos(md.selectionStart);
|
||||||
|
}
|
||||||
|
else if (getnote(title))
|
||||||
{
|
{
|
||||||
showtemporaryinfo("'" + title + "' already exists");
|
showtemporaryinfo("'" + title + "' already exists");
|
||||||
|
setpos(md.selectionStart);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -403,11 +415,17 @@ function includesub()
|
||||||
var title = linkatpos();
|
var title = linkatpos();
|
||||||
if (confirm("Replace [[" + title + "]] by its content?"))
|
if (confirm("Replace [[" + title + "]] by its content?"))
|
||||||
{
|
{
|
||||||
|
var subnote = getnote(title);
|
||||||
md.value =
|
md.value =
|
||||||
md.value.substring(0, range.start)
|
md.value.substring(0, range.start)
|
||||||
+ getnote(title).content
|
+ subnote.content
|
||||||
+ md.value.substring(range.end);
|
+ md.value.substring(range.end);
|
||||||
|
|
||||||
|
if (confirm("Delete '" + title + "'?"))
|
||||||
|
{
|
||||||
|
deletenote(subnote);
|
||||||
|
}
|
||||||
|
|
||||||
datachanged();
|
datachanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1215,12 +1233,6 @@ function unfoldall()
|
||||||
|
|
||||||
function checkfolding()
|
function checkfolding()
|
||||||
{
|
{
|
||||||
if (!settings.enablefolding)
|
|
||||||
{
|
|
||||||
console.log("folding is disabled.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var range = getlinesrange();
|
var range = getlinesrange();
|
||||||
var line = md.value.substring(range.start, range.end);
|
var line = md.value.substring(range.start, range.end);
|
||||||
var sectionmark = sectionmarks.find(m => line.startsWith(m));
|
var sectionmark = sectionmarks.find(m => line.startsWith(m));
|
||||||
|
@ -1256,8 +1268,16 @@ function checkfolding()
|
||||||
}
|
}
|
||||||
|
|
||||||
md.setSelectionRange(range.start, sectionend);
|
md.setSelectionRange(range.start, sectionend);
|
||||||
|
|
||||||
|
if (settings.enablefolding)
|
||||||
|
{
|
||||||
fold();
|
fold();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
createsubnote(currentnote.title + " -" + line.replace(/#/g, ""));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (isfold(line))
|
else if (isfold(line))
|
||||||
{
|
{
|
||||||
|
@ -1775,18 +1795,22 @@ function rename(newname)
|
||||||
return "";
|
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 + '"?'))
|
if (confirm('delete "' + currentnote.title + '"?'))
|
||||||
{
|
{
|
||||||
var trash = JSON.parse(window.localStorage.getItem("trash")) || [];
|
deletenote(currentnote);
|
||||||
trash.push(currentnote);
|
|
||||||
window.localStorage.setItem("trash", JSON.stringify(trash));
|
|
||||||
|
|
||||||
localdata = localdata.filter(n => n != currentnote);
|
|
||||||
|
|
||||||
renamereferences(currentnote.title + " (deleted)");
|
|
||||||
|
|
||||||
loadlast();
|
loadlast();
|
||||||
datachanged();
|
datachanged();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue