added: use search list to ask questions

This commit is contained in:
quenousimporte 2023-02-01 14:19:31 +01:00
parent d91158e752
commit 9a0edbc421
1 changed files with 23 additions and 6 deletions

29
main.js
View File

@ -354,6 +354,19 @@ var snippets = [
cursor: 0
}];
function ask(question)
{
return new Promise( (resolve) =>
{
filter.placeholder = question;
return searchinlist(["Yes", "No"])
.then(answer =>
{
resolve(answer);
});
});
}
function getnote(title)
{
return localdata.find(note => note.title == title);
@ -413,21 +426,25 @@ function includesub()
if (range)
{
var title = linkatpos();
if (confirm("Replace [[" + title + "]] by its content?"))
ask("Replace [[" + title + "]] by its content?")
.then( (answser) =>
{
if (answser != "Yes") return;
var subnote = getnote(title);
md.value =
md.value.substring(0, range.start)
+ subnote.content
+ md.value.substring(range.end);
if (confirm("Delete '" + title + "'?"))
ask("Delete '" + title + "'?")
.then( (answser) =>
{
if (answser != "Yes") return;
deletenote(subnote);
}
datachanged();
}
})
.finally(datachanged);
});
}
}