parent
0d436b0516
commit
67ce656365
52
main.js
52
main.js
|
@ -1654,7 +1654,10 @@ function commandpalette()
|
||||||
suffix: [s.command]
|
suffix: [s.command]
|
||||||
};
|
};
|
||||||
}))
|
}))
|
||||||
.concat(Object.values(metadata).map(item =>
|
.concat(Object.values(metadata)
|
||||||
|
.filter(item => !item.deleted)
|
||||||
|
.sort( (i,j) => j.lastchanged - i.lastchanged)
|
||||||
|
.map(item =>
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
prefix: "note ",
|
prefix: "note ",
|
||||||
|
@ -2301,9 +2304,12 @@ function toggletitle()
|
||||||
|
|
||||||
function selectnote()
|
function selectnote()
|
||||||
{
|
{
|
||||||
// todo: sort by lastchanged
|
|
||||||
return searchinlist(
|
return searchinlist(
|
||||||
Object.values(metadata).map(item =>
|
Object
|
||||||
|
.values(metadata)
|
||||||
|
.filter(item => !item.deleted)
|
||||||
|
.sort( (i,j) => j.lastchanged - i.lastchanged)
|
||||||
|
.map(item =>
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
text: item.title,
|
text: item.title,
|
||||||
|
@ -2431,42 +2437,26 @@ function renamereferences(newname)
|
||||||
|
|
||||||
function restoredeleted()
|
function restoredeleted()
|
||||||
{
|
{
|
||||||
// todo: parse local storage starting with "deleted" and reindex with a new guid
|
searchinlist(Object.values(metadata).filter(i => i.deleted).sort( (i,j) => j.lastchanged - i.lastchanged).map(i => i.title))
|
||||||
var trash = window.localStorage.getItem("trash");
|
.then(title =>
|
||||||
if (trash)
|
|
||||||
{
|
{
|
||||||
trash = JSON.parse(window.localStorage.getItem("trash"));
|
if (confirm("Restore " + title + "?"))
|
||||||
searchinlist(trash.map(note => note.title + " - deleted on " + note.deletiondate))
|
|
||||||
.then(item =>
|
|
||||||
{
|
{
|
||||||
if (confirm("Restore " + item + "?"))
|
var guid = getguid(title);
|
||||||
{
|
metadata[guid].deleted = false;
|
||||||
var title = item.split(" - deleted on ").shift();
|
metadata[guid].lastchanged = Date.now();
|
||||||
var stamp = item.split(" - deleted on ").pop();
|
renameinternallinks(title + " (deleted)", title);
|
||||||
var index = trash.findIndex(n => n.title == title && (!n.deletiondate || n.deletiondate == stamp));
|
localStorage.setItem("index", JSON.stringify(metadata));
|
||||||
if (index > -1)
|
|
||||||
{
|
|
||||||
var notetorestore = trash.splice(index, 1).pop();
|
|
||||||
notetorestore.title += " - restored on " + timestamp();
|
|
||||||
delete notetorestore.deletiondate;
|
|
||||||
localdata.unshift(notetorestore);
|
|
||||||
loadnote(notetorestore.title);
|
|
||||||
datachanged();
|
|
||||||
window.localStorage.setItem("trash", JSON.stringify(trash));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function deletenote(title)
|
function deletenote(title)
|
||||||
{
|
{
|
||||||
var guid = getguid(title);
|
var guid = getguid(title);
|
||||||
delete metadata[guid];
|
metadata[guid].deleted = true;
|
||||||
|
metadata[guid].lastchanged = Date.now();
|
||||||
renameinternallinks(title, title + " (deleted)");
|
renameinternallinks(title, title + " (deleted)");
|
||||||
var content = localStorage.getItem(guid);
|
|
||||||
localStorage.removeItem(guid);
|
|
||||||
localStorage.setItem("deleted_" + title, content);
|
|
||||||
localStorage.setItem("index", JSON.stringify(metadata));
|
localStorage.setItem("index", JSON.stringify(metadata));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2692,6 +2682,10 @@ function renameinternallinks(from, to)
|
||||||
if (content != newcontent)
|
if (content != newcontent)
|
||||||
{
|
{
|
||||||
localStorage.setItem(guid, newcontent);
|
localStorage.setItem(guid, newcontent);
|
||||||
|
if (item.title == window.title.value)
|
||||||
|
{
|
||||||
|
seteditorcontent(newcontent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue