diff --git a/README.md b/README.md
index 241a2e7..8169624 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,7 @@ For instance, it converts quotes like `"these"` to `βtheseβ`, which are typo
Additionally, you can convert text into more than 20 different font styles and casing changes.
You can enable and disable any features in the options and adjust more settings regarding the behavior of the add-on.
-This extension works with modern Firefox v78 or higher, Chromium/Chrome and Thunderbird v78 or higher.
+This extension works with modern Firefox v87 or higher, Chromium/Chrome and Thunderbird v87 or higher.
## Download
diff --git a/assets/texts/en/amoDescription.html b/assets/texts/en/amoDescription.html
index 6419f10..de1aafa 100644
--- a/assets/texts/en/amoDescription.html
+++ b/assets/texts/en/amoDescription.html
@@ -83,7 +83,7 @@
The add-on is free/libre open-source software and developed on GitHub. Fork it on GitHub and contribute.
There are some easy issues to start with.
-This extension works with modern Firefox and Thunderbird v78 or higher.
+This extension works with modern Firefox and Thunderbird v87 or higher.
πββοΈ Contribute πββοΈ
diff --git a/scripts/manifests/dev.json b/scripts/manifests/dev.json
index 378e20d..9223efd 100644
--- a/scripts/manifests/dev.json
+++ b/scripts/manifests/dev.json
@@ -44,7 +44,7 @@
"applications": {
"gecko": {
"id": "unicodify@rugk.github.io",
- "strict_min_version": "78.0"
+ "strict_min_version": "87.0"
}
}
}
diff --git a/scripts/manifests/firefox.json b/scripts/manifests/firefox.json
index 0ce1b72..0075adb 100644
--- a/scripts/manifests/firefox.json
+++ b/scripts/manifests/firefox.json
@@ -42,7 +42,7 @@
"applications": {
"gecko": {
"id": "unicodify@rugk.github.io",
- "strict_min_version": "78.0"
+ "strict_min_version": "87.0"
}
}
}
diff --git a/scripts/manifests/thunderbirdmanifest.json b/scripts/manifests/thunderbirdmanifest.json
index a7974b0..5068e68 100644
--- a/scripts/manifests/thunderbirdmanifest.json
+++ b/scripts/manifests/thunderbirdmanifest.json
@@ -45,7 +45,7 @@
"applications": {
"gecko": {
"id": "unicodify@rugk.github.io",
- "strict_min_version": "78.0"
+ "strict_min_version": "87.0"
}
}
}
diff --git a/src/content_scripts/autocorrect.js b/src/content_scripts/autocorrect.js
index 1fa9d3b..9a0a3cb 100644
--- a/src/content_scripts/autocorrect.js
+++ b/src/content_scripts/autocorrect.js
@@ -266,9 +266,8 @@ function firstDifferenceIndex(a, b) {
* @returns {void}
*/
function autocorrect(event) {
- // console.log('keydown', event.key, event.key.length, event.keyCode);
- // Exclude all keys that do not produce a single Unicode character
- if (!((event.key.length === 0 || event.key.length === 1 || event.keyCode === 13 || event.key === "Unidentified") && !event.ctrlKey && !event.metaKey && !event.altKey)) {
+ // console.log('beforeinput', event.inputType, event.data);
+ if (!(event.inputType === "insertText" || event.inputType === "insertCompositionText" || event.inputType === "insertParagraph" || event.inputType === "insertLineBreak")) {
return;
}
if (!symbolpatterns) {
@@ -279,11 +278,12 @@ function autocorrect(event) {
if (caretposition) {
const value = target.value || target.innerText;
let deletecount = 0;
- let insert = value.slice(caretposition - 1, caretposition); // event.key;
+ let insert = event.inputType === "insertLineBreak" || event.inputType === "insertParagraph" ? "\n" : event.data;
+ const inserted = insert;
let output = false;
// Use Unicode smart quotes
if (quotes && (insert === "'" || insert === '"')) {
- const previouschar = value.slice(caretposition < 2 ? 0 : caretposition - 2, caretposition - 1);
+ const previouschar = value.slice(caretposition < 1 ? 0 : caretposition - 1, caretposition);
// White space
const re = /^\s*$/;
if (insert === "'") {
@@ -291,19 +291,19 @@ function autocorrect(event) {
} else if (insert === '"') {
insert = re.test(previouschar) ? "β" : "β";
}
- deletecount = 1;
output = true;
}
- const previousText = value.slice(caretposition < (longest + 1) ? 0 : caretposition - (longest + 1), caretposition - 1);
+ const previousText = value.slice(caretposition < longest ? 0 : caretposition - longest, caretposition);
const regexResult = symbolpatterns.exec(previousText);
// Autocorrect Unicode Symbols
if (regexResult) {
- const text = value.slice(caretposition < longest ? 0 : caretposition - longest, caretposition);
+ const length = longest - 1;
+ const text = value.slice(caretposition < length ? 0 : caretposition - length, caretposition) + inserted;
const aregexResult = symbolpatterns.exec(text);
const aaregexResult = antipatterns.exec(text);
if (!aaregexResult && (!aregexResult || (caretposition <= longest ? regexResult.index < aregexResult.index : regexResult.index <= aregexResult.index))) {
- insert = autocorrections[regexResult[0]] + (event.keyCode === 13 ? "\n" : insert);
- deletecount = regexResult[0].length + 1;
+ insert = autocorrections[regexResult[0]] + inserted;
+ deletecount = regexResult[0].length;
output = true;
}
} else {
@@ -312,17 +312,17 @@ function autocorrect(event) {
// Numbers regular expression: https://regex101.com/r/7jUaSP/10
// Do not match version numbers: https://github.com/rugk/unicodify/issues/40
const numberRegex = /(?\.\d+)?$/;
- const previousText = value.slice(0, caretposition - 1);
+ const previousText = value.slice(0, caretposition);
const regexResult = numberRegex.exec(previousText);
if (regexResult && insert !== ".") {
- const text = value.slice(0, caretposition);
+ const text = value.slice(0, caretposition) + inserted;
const aregexResult = numberRegex.exec(text);
if (!aregexResult) {
const label = outputLabel(regexResult[0], regexResult.groups.fractionpart);
const index = firstDifferenceIndex(label, regexResult[0]);
if (index >= 0) {
- insert = label.slice(index) + (event.keyCode === 13 ? "\n" : insert);
- deletecount = regexResult[0].length - index + 1;
+ insert = label.slice(index) + inserted;
+ deletecount = regexResult[0].length - index;
output = true;
}
}
@@ -330,13 +330,17 @@ function autocorrect(event) {
}
}
if (output) {
- const text = value.slice(caretposition - deletecount, caretposition);
- deleteCaret(target, text);
+ event.preventDefault();
+
+ const text = deletecount ? value.slice(caretposition - deletecount, caretposition) : "";
+ if (text) {
+ deleteCaret(target, text);
+ }
insertAtCaret(target, insert);
- console.debug("Autocorrect: β%sβ was replaced with β%sβ.", text, insert);
insertedText = insert;
- deletedText = text;
+ deletedText = text + inserted;
+ console.debug("Autocorrect: β%sβ was replaced with β%sβ.", deletedText, insertedText);
lastTarget = target;
lastCaretPosition = caretposition - deletecount + insert.length;
@@ -351,9 +355,9 @@ function autocorrect(event) {
* @returns {void}
*/
function undoAutocorrect(event) {
- // console.log('keyup', event.key, event.key.length, event.keyCode);
+ // console.log('beforeinput', event.inputType, event.data);
// Backspace
- if (!(event.keyCode === 8 && !event.ctrlKey && !event.metaKey && !event.altKey)) {
+ if (event.inputType !== "deleteContentBackward") {
return;
}
const target = event.target;
@@ -363,6 +367,7 @@ function undoAutocorrect(event) {
event.preventDefault();
if (insertedText) {
+ lastTarget = null;
deleteCaret(target, insertedText);
}
if (deletedText) {
@@ -370,9 +375,9 @@ function undoAutocorrect(event) {
}
console.debug("Undo autocorrect: β%sβ was replaced with β%sβ.", insertedText, deletedText);
}
- }
- lastTarget = null;
+ lastTarget = null;
+ }
}
/**
@@ -407,6 +412,6 @@ function handleError(error) {
browser.runtime.sendMessage({ "type": AUTOCORRECT_CONTENT }).then(handleResponse, handleError);
browser.runtime.onMessage.addListener(handleResponse);
-window.addEventListener("keydown", undoAutocorrect, true);
-window.addEventListener("keyup", autocorrect, true);
+window.addEventListener("beforeinput", undoAutocorrect, true);
+window.addEventListener("beforeinput", autocorrect, true);
console.log("Unicodify autocorrect module loaded.");
diff --git a/src/manifest.json b/src/manifest.json
index 378e20d..9223efd 100644
--- a/src/manifest.json
+++ b/src/manifest.json
@@ -44,7 +44,7 @@
"applications": {
"gecko": {
"id": "unicodify@rugk.github.io",
- "strict_min_version": "78.0"
+ "strict_min_version": "87.0"
}
}
}