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

[calc-js@ptandler] Fix enter/return key not recognised + history. #4996

Merged
merged 1 commit into from
Aug 26, 2023

Conversation

fredcw
Copy link
Contributor

@fredcw fredcw commented Aug 9, 2023

Fix enter/return key was not recognised meaning history didn't work.

Fixes: #4851

@ptandler

@rcalixte
Copy link
Member

rcalixte commented Aug 9, 2023

Has this been tested for backwards compatibility? Would it make sense to put the fix into a 5.4 directory and leave the existing in something like a 3.0 directory?

@fredcw
Copy link
Contributor Author

fredcw commented Aug 9, 2023

I'm pretty sure this is backward compatible because it's the same named constants I use in Cinnamenu but I'll check anyway...

@fredcw
Copy link
Contributor Author

fredcw commented Aug 9, 2023

Yes, tested on Mint 20.3 (cinnamon 5.2) which is an earlier version of Clutter and both keypad enter and return work so I guess Clutter.KEY_Return was backward compatible.

Btw, this applet doesn't work on Mint versions prior to 20.1 (cinnamon 4.8) due to it's use of Intl.NumberFormat().formatToParts() I guess this should probably be documented in the readme as I don't think there's any way to prevent it from being installed on earlier versions of Mint and just failing to work.

@ghost
Copy link

ghost commented Aug 9, 2023

Btw, this applet doesn't work on Mint versions prior to 20.1 (cinnamon 4.8) due to it's use of Intl.NumberFormat().formatToParts()

It will work with a simple modification:

this.numberDecimalSeparator = Intl.NumberFormat().format(1/10).replace(/\d/g, "");

instead of

const numberParts = Intl.NumberFormat().formatToParts(1234.5);
this.numberDecimalSeparator = numberParts.find(part => part.type === 'decimal').value;

in initializeNumberFormat().
Of course this was very shortly tested in Mint 19.2 (Cinnamon 4.2.4) using en_US default locale.
If anyone has more extensive testing capabilities they could confirm - or not - the validity of this change.

It could even be put in a try/catch in order to retain the newer functionality for a future time when backward compatibility won't be an issue anymore:

initializeNumberFormat() {
  // see e.g. https://stackoverflow.com/a/51411310/1480587 and https://stackoverflow.com/a/62694190/1480587
  try{
    const numberParts = Intl.NumberFormat().formatToParts(1234.5);
    // e.g. [{"type":"integer","value":"1"},{"type":"group","value":"."},{"type":"integer","value":"234"},{"type":"decimal","value":","},{"type":"fraction","value":"5"}]
    // this.numberGroupSeparator = numberParts.find(part => part.type === 'group').value;
    this.numberDecimalSeparator = numberParts.find(part => part.type === 'decimal').value;
  } catch(e){
    this.numberDecimalSeparator = Intl.NumberFormat().format(1/10).replace(/\d/g, "");
  }
  // helpers for `updateResult()` in case `this.opt.convertLocaleNumberSeparators` is set
  // build reg exps to search for group separators (should be removed) ...
  // this.numberGroupRegExp = new RegExp(`\\d${escapeRegExp(this.numberGroupSeparator)}\\d`);
  /// ... and then for decimal separators (which should be replaced by ".")
  this.numberDecimalRegExp = new RegExp(`(\\d+)${escapeRegExp(this.numberDecimalSeparator)}(\\d+)`, "g");
}

@brownsr brownsr merged commit f6185f3 into linuxmint:master Aug 26, 2023
@fredcw fredcw deleted the calc-js3 branch August 26, 2023 11:35
@ptandler
Copy link
Contributor

ptandler commented Aug 27, 2023

Thank you so much for fixing this 😍 @brownsr

Should we move the "Mint versions prior to 20.1 (cinnamon 4.8)" issue to a separate issue/PR?

I think the approach with try/catch is a good way to provide compatibility.

I don't have a Mint < 20.3 at hand - and currently I also don't have much time to work on this.

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.

Question Regarding Usage : calc-js@ptandler
4 participants