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

Exponentiation on the web interface #97

Closed
MonaMayrhofer opened this issue Aug 13, 2022 · 5 comments
Closed

Exponentiation on the web interface #97

MonaMayrhofer opened this issue Aug 13, 2022 · 5 comments

Comments

@MonaMayrhofer
Copy link
Contributor

Exponentiation does not seem to work in the web interface (Firefox).

As the web interface immediately converts the input into special symbols it is not possible to do inputs such as 2**3 as these get immediately turned into 2⋅⋅3, which then results in Unexpected token: 'Star'

Also I am not able to input ^2 for some reason as the circumflex gets immediately deleted.

The console version works fine.

@PaddiM8
Copy link
Owner

PaddiM8 commented Sep 22, 2022

Not sure why the circumflex would be deleted. I can't reproduce that on my machine. However, I now made sure a⋅⋅b gets parsed as a^b in the latest commit.

@MonaMayrhofer
Copy link
Contributor Author

Thanks!

I think its because I'm on a german quertz keyboard and entering a circumflex would start to create a compose key input. Like the sequence ^ a results in â. If i actually want to type a circumflex, I would have to type ^ ^. The first circumflex to enter composing mode, and the second one to confirm the compose as "yes i would like a circumflex". The same thing is with keys like ` and ´

In the oninput event this behaviour seems to be handled with specifying the composed and isComposed properties in the event.

In total there are 4 oninput events that are triggered:

First: ^

  • {"isComposing":true,"composed":true,"inputType":"insertCompositionText","data":"^"}

Second: ^

  • {"isComposing":true,"composed":true,"inputType":"insertCompositionText","data":""}
  • {"isComposing":false,"composed":true,"inputType":"insertCompositionText","data":""}
  • {"isComposing":false,"composed":true,"inputType":"insertText","data":"^"}

Note that the circumflex immediately disappears after typing the first one - without any further interaction... So my guess would be that the whole composition cycle gets somehow cancelled and therefore deletes the "fake" circumflex that indicates that i am in the composing mode...

Here is some more info on that bizz.

@MonaMayrhofer
Copy link
Contributor Author

I managed to reproduce these shenanigans:

<html>

<head>
  <script>
    function inp(e) {
      let b = document.getElementById("blub");

      e.target.selectionStart = e.target.selectionStart;
      e.target.selectionEnd = e.target.selectionStart;
    }
  </script>
</head>

<textarea id="blub" oninput="inp(event)"></textarea>

</html>

So i guess the problem is that when I enter the composing mode by entering the first circumflex, the selection of the textfield is immediately updated, which is interpreted by the browser as "the cursor moved so we need to cancel the composing"

If i wrap the changing of the selection in an if, then it works.

<html>

<head>
  <script>
    function inp(e) {
      let b = document.getElementById("blub");

      if (e.inputType !== "insertCompositionText") {
        e.target.selectionStart = e.target.selectionStart;
        e.target.selectionEnd = e.target.selectionStart;
      }
    }
  </script>
</head>

<textarea id="blub" oninput="inp(event)"></textarea>

</html>

Maybe inserting a similar if here solves the issue....

function handleInput(e: Event) {
if (ignoreNextInput) {
ignoreNextInput = false;
return;
}
const event = e as InputEvent;
const target = event.target as HTMLInputElement;
setText(target.value == "\n" ? "" : target.value);
if (event.data == "(") {
insertText(")");
offsetCaret(-1);
}
}

But I am not at all aware of any side effects this may have, and I know nearly nothing about this whole key composing stuff myself, so take all of this with a grain of salt, should you or someone else decide to look into this rabbithole.

@MonaMayrhofer
Copy link
Contributor Author

This would be a very quick fix for it, that seems to work reasonably well: MonaMayrhofer@77bd037. Normally the circumflex would be somehow highlighted as being "fake", (normally underlined), but that would not be as straight forward to implement.

Well that's it for me for now, I don't know how many users are actually affected by this (i personally thought this was standard behavior but as you cannot reproduce it, it does not seem to be as standard).

@PaddiM8
Copy link
Owner

PaddiM8 commented Oct 29, 2022

@MonaMayrhofer That looks like a reasonable fix and doesn't seem to cause any issues, neat. Feel free to make a pull request!

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

No branches or pull requests

2 participants