Add option to disable translation in text fields
This commit is contained in:
parent
6f43d626f0
commit
4a6f907c73
|
@ -85,6 +85,12 @@
|
|||
"ifChangeSecondLangOnPageCaptionLabel": {
|
||||
"message": "Detects the language of the selected text, and if it is the same as the default target language, translate it into the second language."
|
||||
},
|
||||
"isDisabledInTextFieldsLabel": {
|
||||
"message": "Disable translation in text fields"
|
||||
},
|
||||
"isDisabledInTextFieldsCaptionLabel": {
|
||||
"message": "Don't display translation button or panel when selecting text in a text field."
|
||||
},
|
||||
"disableUrlListLabel": {
|
||||
"message": "URL list to disable translation"
|
||||
},
|
||||
|
|
|
@ -34,6 +34,10 @@ const handleMouseUp = async e => {
|
|||
prevSelectedText = selectedText;
|
||||
if (selectedText.length === 0) return;
|
||||
|
||||
if (getSettings("isDisabledInTextFields")) {
|
||||
if (isInContentEditable()) return;
|
||||
}
|
||||
|
||||
const clickedPosition = { x: e.clientX, y: e.clientY };
|
||||
const selectedPosition = getSelectedPosition();
|
||||
showTranslateContainer(selectedText, selectedPosition, clickedPosition);
|
||||
|
@ -82,6 +86,13 @@ const getSelectedPosition = () => {
|
|||
return selectedPosition;
|
||||
};
|
||||
|
||||
const isInContentEditable = () => {
|
||||
const element = document.activeElement;
|
||||
if (element.tagName === "INPUT" || element.tagName === "TEXTAREA") return true;
|
||||
if (element.contentEditable === "true") return true;
|
||||
return false;
|
||||
};
|
||||
|
||||
const handleKeyDown = e => {
|
||||
if (e.key === "Escape") {
|
||||
removeTranslatecontainer();
|
||||
|
|
|
@ -94,14 +94,21 @@ export default [
|
|||
type: "checkbox",
|
||||
default: false
|
||||
},
|
||||
{
|
||||
id: "isDisabledInTextFields",
|
||||
title: "isDisabledInTextFieldsLabel",
|
||||
captions: ["isDisabledInTextFieldsCaptionLabel"],
|
||||
type: "checkbox",
|
||||
default: false,
|
||||
new: true
|
||||
},
|
||||
{
|
||||
id: "disableUrlList",
|
||||
title: "disableUrlListLabel",
|
||||
captions: ["disableUrlListCaptionLabel"],
|
||||
type: "textarea",
|
||||
default: "",
|
||||
placeholder: "https://example.com/*\nhttps://example.net/*",
|
||||
new: true
|
||||
placeholder: "https://example.com/*\nhttps://example.net/*"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue