Add confirmation prompt for inserting AI response when no text is selected. See #353
This commit is contained in:
parent
c15fcb466e
commit
81a1bfb9c8
2 changed files with 13 additions and 2 deletions
|
|
@ -1270,5 +1270,9 @@
|
||||||
"CORS_give_allurls_perm": {
|
"CORS_give_allurls_perm": {
|
||||||
"message": "Give \"all URLs\" permission",
|
"message": "Give \"all URLs\" permission",
|
||||||
"description": ""
|
"description": ""
|
||||||
|
},
|
||||||
|
"Replace_No_Selected_Text": {
|
||||||
|
"message": "No text selected, would you like to insert the AI's response at the beginning of the email?",
|
||||||
|
"description": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -24,12 +24,19 @@ switch (message.command) {
|
||||||
|
|
||||||
case "replaceSelectedText": {
|
case "replaceSelectedText": {
|
||||||
const selectedText = window.getSelection().toString();
|
const selectedText = window.getSelection().toString();
|
||||||
|
let force_insert = false;
|
||||||
if (selectedText === '') {
|
if (selectedText === '') {
|
||||||
return Promise.resolve(false);
|
if(!confirm(browser.i18n.getMessage("Replace_No_Selected_Text"))) {
|
||||||
|
return Promise.resolve(false);
|
||||||
|
}else{
|
||||||
|
force_insert = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const sel = window.getSelection();
|
const sel = window.getSelection();
|
||||||
if (!sel || sel.type !== "Range" || !sel.rangeCount) {
|
if (!sel || sel.type !== "Range" || !sel.rangeCount) {
|
||||||
return Promise.resolve(false);
|
if(!force_insert) {
|
||||||
|
return Promise.resolve(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const r = sel.getRangeAt(0);
|
const r = sel.getRangeAt(0);
|
||||||
r.deleteContents();
|
r.deleteContents();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue