From 33ed2f21ad9a007ef42b1621181a604c8fa45d3b Mon Sep 17 00:00:00 2001 From: Teal Dulcet Date: Mon, 17 May 2021 00:56:35 -0700 Subject: [PATCH 1/5] Updated autocorrect to not match version numbers. --- src/content_scripts/autocorrect.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/content_scripts/autocorrect.js b/src/content_scripts/autocorrect.js index c03ecf7..741b368 100644 --- a/src/content_scripts/autocorrect.js +++ b/src/content_scripts/autocorrect.js @@ -309,15 +309,16 @@ function autocorrect(event) { } else { // Convert fractions and mathematical constants to Unicode characters if (!output && fracts) { - // Numbers: https://regex101.com/r/7jUaSP/2 - const numberRegex = /[0-9]+(\.[0-9]+)?$/; + // 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 regexResult = numberRegex.exec(previousText); - if (regexResult) { + if (regexResult && insert !== ".") { const text = value.slice(0, caretposition); const aregexResult = numberRegex.exec(text); if (!aregexResult) { - const label = outputLabel(regexResult[0], regexResult[1]); + 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); From aca9edcd6ebd39b621e33cc839d2efc9af6d8894 Mon Sep 17 00:00:00 2001 From: Teal Dulcet Date: Mon, 17 May 2021 01:00:24 -0700 Subject: [PATCH 2/5] Improved toggle case performance. --- .github/FUNDING.yml | 1 + src/common/modules/UnicodeTransformationHandler.js | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..e947178 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: [rugk, tdulcet] diff --git a/src/common/modules/UnicodeTransformationHandler.js b/src/common/modules/UnicodeTransformationHandler.js index 4e95fd4..8f6c664 100644 --- a/src/common/modules/UnicodeTransformationHandler.js +++ b/src/common/modules/UnicodeTransformationHandler.js @@ -53,6 +53,7 @@ export function getTransformationType(transformationId) { function capitalizeEachWord(text) { // Regular expression Unicode property escapes and lookbehind assertions require Firefox/Thunderbird 78 // see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#bcd:javascript.builtins.RegExp + // \p{Alphabetic} return text.replace(/(?<=^|\P{Alpha})\p{Alpha}\S*/gu, ([h, ...t]) => h.toLocaleUpperCase() + t.join("")); } @@ -110,12 +111,13 @@ function toggleCase(atext) { let output = ""; for (let letter of atext) { - const upper = letter.toLocaleUpperCase(); - const lower = letter.toLocaleLowerCase(); - if (letter === lower && letter !== upper) { - letter = upper; - } else if (letter === upper && letter !== lower) { - letter = lower; + // \p{Changes_When_Uppercased} + if (/\p{CWU}/u.test(letter)) { + letter = letter.toLocaleUpperCase(); + } + // \p{Changes_When_Lowercased} + else if (/\p{CWL}/u.test(letter)) { + letter = letter.toLocaleLowerCase(); } output += letter; } From 0150c02454bcdc04bf44f0e8aabc599215ae4488 Mon Sep 17 00:00:00 2001 From: Teal Dulcet Date: Wed, 19 May 2021 02:28:54 -0700 Subject: [PATCH 3/5] Made more minor bug fixes. --- scripts/manifests/thunderbirdmanifest.json | 1 - src/background/modules/ContextMenu.js | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/manifests/thunderbirdmanifest.json b/scripts/manifests/thunderbirdmanifest.json index a7974b0..1de1d40 100644 --- a/scripts/manifests/thunderbirdmanifest.json +++ b/scripts/manifests/thunderbirdmanifest.json @@ -36,7 +36,6 @@ "permissions": [ "storage", - "", "tabs", "compose", "menus" diff --git a/src/background/modules/ContextMenu.js b/src/background/modules/ContextMenu.js index d97dcfb..692b88e 100644 --- a/src/background/modules/ContextMenu.js +++ b/src/background/modules/ContextMenu.js @@ -50,6 +50,10 @@ function handleMenuChoosen(info, tab) { * @throws {Error} */ async function handleMenuShown(info) { + if (!info.editable) { + return; + } + let text = info.selectionText; // do not show menu entry when no text is selected @@ -140,6 +144,7 @@ async function addMenuItems(menuItems, unicodeFontSettings = lastCachedUnicodeFo if (unicodeFontSettings.showReadableText) { menuText = browser.i18n.getMessage("menuReadableTextWrapper", [translatedMenuText, transformedText]); } + menuText = menuText.replaceAll("&", "&&"); if (refreshMenu) { menus.update(transformationId, { From b94f2caa3c0952d0b011d5999b0dc592e911ac35 Mon Sep 17 00:00:00 2001 From: Teal Dulcet Date: Wed, 19 May 2021 02:31:56 -0700 Subject: [PATCH 4/5] Fixed indentation on options page. --- src/options/options.html | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/options/options.html b/src/options/options.html index c56bca5..51a51b8 100644 --- a/src/options/options.html +++ b/src/options/options.html @@ -53,17 +53,16 @@
-
    -

    Unicode autocorrection

    - - You can configure the automatic corrections that are done when you are typing text here.
    - All the autocorrections are done after typing the first nonmatching character following the character sequence, such as a space (␣). Press Backspace (⌫) to undo an autocorrection. - Only the quotes replacement is done immediately. +

    Unicode autocorrection

    + + You can configure the automatic corrections that are done when you are typing text here.
    + All the autocorrections are done after typing the first nonmatching character following the character sequence, such as a space (␣). Press Backspace (⌫) to undo an autocorrection. + Only the quotes replacement is done immediately.

    - - For Emoji autocorrection, including :colon: shortcodes and Emoticons, please also try out our 🤩 Awesome Emoji Picker add-on. - - + + For Emoji autocorrection, including :colon: shortcodes and Emoticons, please also try out our 🤩 Awesome Emoji Picker add-on. + +
    • @@ -93,11 +92,11 @@

      Unicode autocorrection

      -
        -

        Context menu

        - Write, select text and choose the corresponding option in the context menu to quickly change the character style or capitalization. - This is useful on websites that do not support changing the font or text formatting. +

        Context menu

        + Write, select text and choose the corresponding option in the context menu to quickly change the character style or capitalization. + This is useful on websites that do not support changing the font or text formatting. +
        • From 9538ac77b2395e9776873eaca9357b230a3db62a Mon Sep 17 00:00:00 2001 From: Teal Dulcet Date: Tue, 22 Jun 2021 02:57:35 -0700 Subject: [PATCH 5/5] More fixes and improvements. --- .eslintrc | 2 +- scripts/manifests/chromemanifest.json | 2 +- scripts/manifests/thunderbirdmanifest.json | 1 + src/background/modules/AutocorrectHandler.js | 11 +++-------- src/background/modules/ContextMenu.js | 2 +- src/content_scripts/autocorrect.js | 2 +- 6 files changed, 8 insertions(+), 12 deletions(-) diff --git a/.eslintrc b/.eslintrc index 8ed12dd..e361a86 100644 --- a/.eslintrc +++ b/.eslintrc @@ -10,7 +10,7 @@ "env": { "browser": true, "webextensions": true, - "es6": true + "es2021": true }, "extends": "eslint:recommended", "rules": { diff --git a/scripts/manifests/chromemanifest.json b/scripts/manifests/chromemanifest.json index cf69111..5dbdbc7 100644 --- a/scripts/manifests/chromemanifest.json +++ b/scripts/manifests/chromemanifest.json @@ -1,6 +1,6 @@ { "manifest_version": 2, - "name": "Unicodify DEV VERSION", + "name": "__MSG_extensionName__", "short_name": "__MSG_extensionNameShort__", "version": "0.1", "author": "Teal Dulcet, rugk", diff --git a/scripts/manifests/thunderbirdmanifest.json b/scripts/manifests/thunderbirdmanifest.json index 1de1d40..a7974b0 100644 --- a/scripts/manifests/thunderbirdmanifest.json +++ b/scripts/manifests/thunderbirdmanifest.json @@ -36,6 +36,7 @@ "permissions": [ "storage", + "", "tabs", "compose", "menus" diff --git a/src/background/modules/AutocorrectHandler.js b/src/background/modules/AutocorrectHandler.js index bb0326e..4e32109 100644 --- a/src/background/modules/AutocorrectHandler.js +++ b/src/background/modules/AutocorrectHandler.js @@ -18,7 +18,7 @@ let autocorrections = {}; let longest = 0; let symbolpatterns = []; -// Do not autocorrect for these patterns +// Exceptions, do not autocorrect for these patterns let antipatterns = []; // Chrome @@ -48,13 +48,10 @@ function applySettings() { } console.log("Longest autocorrection", longest); - symbolpatterns = []; // Escape special characters const regExSpecialChars = /[.*+?^${}()|[\]\\]/g; - for (const symbol in autocorrections) { - symbolpatterns.push(symbol.replace(regExSpecialChars, "\\$&")); - } + symbolpatterns = Object.keys(autocorrections).map((symbol) => symbol.replace(regExSpecialChars, "\\$&")); // Do not autocorrect for these patterns antipatterns = []; @@ -87,9 +84,7 @@ function applySettings() { antipatterns = antipatterns.filter((item, pos) => antipatterns.indexOf(item) === pos); console.log("Do not autocorrect for these patterns", antipatterns); - for (const [index, symbol] of antipatterns.entries()) { - antipatterns[index] = symbol.replace(regExSpecialChars, "\\$&"); - } + antipatterns = antipatterns.map((symbol) => symbol.replace(regExSpecialChars, "\\$&")); symbolpatterns = new RegExp(`(${symbolpatterns.join("|")})$`); antipatterns = new RegExp(`(${antipatterns.join("|")})$`); diff --git a/src/background/modules/ContextMenu.js b/src/background/modules/ContextMenu.js index 692b88e..ea6ee80 100644 --- a/src/background/modules/ContextMenu.js +++ b/src/background/modules/ContextMenu.js @@ -64,7 +64,7 @@ async function handleMenuShown(info) { // shorten preview text as it may not be shown anyway if (text.length > PREVIEW_STRING_CUT_LENGTH) { // to be sure, we append … anyway, in case some strange OS has a tooltip for context menus or so - text = `${text.substr(0, PREVIEW_STRING_CUT_LENGTH)}…`; + text = `${text.substring(0, PREVIEW_STRING_CUT_LENGTH)}…`; } text = text.normalize(); diff --git a/src/content_scripts/autocorrect.js b/src/content_scripts/autocorrect.js index 741b368..1fa9d3b 100644 --- a/src/content_scripts/autocorrect.js +++ b/src/content_scripts/autocorrect.js @@ -44,7 +44,7 @@ let longest = 0; // Regular expressions let symbolpatterns = null; -// Do not autocorrect for these patterns +// Exceptions, do not autocorrect for these patterns let antipatterns = null; // Thunderbird