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

Added support for converting arbitrary fractions #96

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

tdulcet
Copy link
Collaborator

@tdulcet tdulcet commented Dec 10, 2024

  • Added support for converting arbitrary fractions.
  • Added dedicated option for the fraction autocorrections. Maybe fixes Separate fraction replacements from other options #10
    • Also, changed them to not autocorrect if there is a preceding or succeeding slash character, per a bug report.
  • Added new Sentence case option.
  • Added new outlined Unicode font.
  • Updated to use Intl.Segmenter.
    • Requires Firefox/Thunderbird 125 or greater.
  • Updated to optionally use RegExp.escape if available.
    • Requires Firefox/Thunderbird 134.
  • @rugk - The new menu item and options page changes need to be localized.

Copy link
Owner

@rugk rugk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor code style stuff, but generally this looks really cool! Thanks!

src/common/modules/UnicodeTransformationHandler.js Outdated Show resolved Hide resolved
"⅜": 3 / 8,
"⅝": 5 / 8,
"⅞": 7 / 8
const afractions = Object.freeze({
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, now I don't quite get the different from afractions to fractions? Is it just to have an intermediate variable?

If so, I still don't like that naming by putting a "random" a in front… like maybe name it even fractionsTemp or even better put it out of scope completely, so no one can accidentally use the "intermediate/temp" variable.
Like maybe having a function getFractions or so that defines this inline?

IMHO that would be good.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both fractions variables are used. In order to support the new arbitrary fraction replacements, we need the separate numerator and denominator values for these hardcoded Unicode fraction characters, so I had to add an additional variable.

src/content_scripts/autocorrect.js Outdated Show resolved Hide resolved
src/content_scripts/autocorrect.js Outdated Show resolved Hide resolved
* @returns {string}
*/
function sentenceCase(text) {
return Array.from(segmenter2.segment(text), ({ segment: [h, ...t] }) => h.toLocaleUpperCase() + t.join("")).join("");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

h and t … can we find a long name for that?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(also above)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

h = head and t = tail.

src/common/modules/UnicodeTransformationHandler.js Outdated Show resolved Hide resolved
src/content_scripts/autocorrect.js Show resolved Hide resolved
const result = Object.entries(afractions).find(([, [anumerator, adenominator]]) => anumerator === numerator && adenominator === denominator);
let label;
if (result) {
[label] = result;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhm this syntax looks wild to me… just curious what is that? 😲

Puts it into an array?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just using the destructuring assignment syntax. I find it cleaner than writing the equivalent:

label = result[0];

src/options/options.html Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Separate fraction replacements from other options
2 participants