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 action: restore
}, },
{ {
shortcut: "ctrl+h",
hint: "Insert markdown header", hint: "Insert markdown header",
action: insertheader, action: insertheader,
allowunsaved: true allowunsaved: true
@ -377,6 +376,11 @@ var commands = [
{ {
hint: "Notes by size", hint: "Notes by size",
action: notesbysize action: notesbysize
},
{
hint: "Replace",
shortcut: "ctrl+h",
action: searchandreplace
}]; }];
var snippets = [ var snippets = [
@ -2321,6 +2325,30 @@ function searchandloadnote()
selectnote().then(loadnote); 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() function notesbysize()
{ {
var sortedtitles = localdata.sort( (n1,n2) => { return n2.content.length - n1.content.length}) var sortedtitles = localdata.sort( (n1,n2) => { return n2.content.length - n1.content.length})