Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated autocorrect to not match version numbers #43

Merged
merged 5 commits into from
Jun 26, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: [rugk, tdulcet]
14 changes: 8 additions & 6 deletions src/common/modules/UnicodeTransformationHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
tdulcet marked this conversation as resolved.
Show resolved Hide resolved
return text.replace(/(?<=^|\P{Alpha})\p{Alpha}\S*/gu, ([h, ...t]) => h.toLocaleUpperCase() + t.join(""));
}

Expand Down Expand Up @@ -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}
rugk marked this conversation as resolved.
Show resolved Hide resolved
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;
}
Expand Down
9 changes: 5 additions & 4 deletions src/content_scripts/autocorrect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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+(?<fractionpart>\.\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);
Expand Down