refactor: datachanged in seteditorcontent

This commit is contained in:
quenousimporte 2023-10-11 21:11:27 +02:00
parent 38ca275f64
commit a685285177
1 changed files with 8 additions and 11 deletions

19
main.js
View File

@ -312,10 +312,15 @@ var snippets = [
cursor: -4 cursor: -4
}]; }];
function seteditorcontent(content) function seteditorcontent(content, silent)
{ {
md.value = content; md.value = content;
applycolors(); applycolors();
if (!silent)
{
datachanged();
}
} }
function encryptstring(str) function encryptstring(str)
@ -426,7 +431,6 @@ function createsubnote(suggestedtitle)
seteditorcontent(md.value.substring(0, range.start) seteditorcontent(md.value.substring(0, range.start)
+ "[[" + title + "]]" + "[[" + title + "]]"
+ md.value.substring(range.end)); + md.value.substring(range.end));
datachanged();
} }
}); });
} }
@ -456,7 +460,6 @@ function includesub()
if (confirm("Delete '" + title + "'?")) if (confirm("Delete '" + title + "'?"))
{ {
deletenote(subnote); deletenote(subnote);
datachanged();
} }
} }
} }
@ -1522,7 +1525,6 @@ function sortselection()
var selection = content.substring(range.start, range.end); var selection = content.substring(range.start, range.end);
var sorted = selection.split("\n").sort().join("\n"); var sorted = selection.split("\n").sort().join("\n");
seteditorcontent(content.substring(0, range.start) + sorted + content.substring(range.end)); seteditorcontent(content.substring(0, range.start) + sorted + content.substring(range.end));
datachanged();
} }
function selectlines() function selectlines()
@ -1734,7 +1736,6 @@ function insert(text, cursoroffset = 0, nbtodelete = 0)
+ text + text
+ content.substring(pos)); + content.substring(pos));
setpos(pos - nbtodelete + text.length + cursoroffset); setpos(pos - nbtodelete + text.length + cursoroffset);
datachanged();
} }
function searchinlist(list, customevent, index) function searchinlist(list, customevent, index)
@ -2268,7 +2269,6 @@ function searchandreplace()
} }
seteditorcontent(md.value.replaceAll(oldvalue, newvalue)); seteditorcontent(md.value.replaceAll(oldvalue, newvalue));
datachanged();
} }
function notesbysize() function notesbysize()
@ -2350,6 +2350,7 @@ function deletenote(note)
localdata = localdata.filter(n => n != note); localdata = localdata.filter(n => n != note);
renamereferences(note.title + " (deleted)"); renamereferences(note.title + " (deleted)");
datachanged();
} }
function deletecurrentnote() function deletecurrentnote()
@ -2358,7 +2359,6 @@ function deletecurrentnote()
{ {
deletenote(currentnote); deletenote(currentnote);
loadlast(); loadlast();
datachanged();
} }
} }
@ -2367,7 +2367,6 @@ function restore()
if (confirm('restore "' + currentnote.title + '"?')) if (confirm('restore "' + currentnote.title + '"?'))
{ {
seteditorcontent(backup); seteditorcontent(backup);
datachanged();
} }
} }
@ -2476,7 +2475,6 @@ function mainkeydownhandler()
var block = lines.splice(start, end - start + 1); var block = lines.splice(start, end - start + 1);
lines.splice(start + direction, 0, ...block); lines.splice(start + direction, 0, ...block);
seteditorcontent(lines.join("\n")); seteditorcontent(lines.join("\n"));
datachanged();
var posshift = direction > 0 ? lines[start].length + 1 : - 1 - lines[end].length; var posshift = direction > 0 ? lines[start].length + 1 : - 1 - lines[end].length;
md.setSelectionRange(pos.start + posshift, pos.end + posshift); md.setSelectionRange(pos.start + posshift, pos.end + posshift);
@ -2574,7 +2572,6 @@ function backspace(nb)
var c = md.value; var c = md.value;
seteditorcontent(c.substring(0, pos - nb) + c.substring(pos)); seteditorcontent(c.substring(0, pos - nb) + c.substring(pos));
setpos(pos - nb); setpos(pos - nb);
datachanged();
} }
function editorkeydown() function editorkeydown()
@ -2745,7 +2742,7 @@ function bindfile(note)
title.value = note.title; title.value = note.title;
setwindowtitle(); setwindowtitle();
seteditorcontent(note.content || ""); seteditorcontent(note.content || "", true);
preview.innerHTML = md2html(md.value); preview.innerHTML = md2html(md.value);
if (changed) if (changed)