diff --git a/main.js b/main.js index ddcb89b..01b69ee 100644 --- a/main.js +++ b/main.js @@ -219,7 +219,6 @@ var commands = [ action: restore }, { - shortcut: "ctrl+h", hint: "Insert markdown header", action: insertheader, allowunsaved: true @@ -377,6 +376,11 @@ var commands = [ { hint: "Notes by size", action: notesbysize +}, +{ + hint: "Replace", + shortcut: "ctrl+h", + action: searchandreplace }]; var snippets = [ @@ -2321,6 +2325,30 @@ function searchandloadnote() selectnote().then(loadnote); } +function searchandreplace() +{ + var oldvalue = prompt("Search:"); + if (!oldvalue) + { + return; + } + + var newvalue = prompt("Replace by:"); + if (!newvalue) + { + return; + } + + var doit = confirm(`Replace '${oldvalue}' by '${newvalue}'?`); + if (!doit) + { + return; + } + + seteditorcontent(md.value.replaceAll(oldvalue, newvalue)); + datachanged(); +} + function notesbysize() { var sortedtitles = localdata.sort( (n1,n2) => { return n2.content.length - n1.content.length})