added: command to search and replace text

This commit is contained in:
quenousimporte 2023-10-09 12:45:50 +02:00
parent cc790f8f89
commit bc2fd50836
1 changed files with 29 additions and 1 deletions

30
main.js
View File

@ -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})