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

how to insert initial value and collapse selection behind existing value #2169

Closed
johanneswilm opened this issue Nov 6, 2023 · 1 comment
Assignees
Labels

Comments

@johanneswilm
Copy link
Contributor

See: https://jsfiddle.net/johanneswilm/6jtzmLe2/7/

Steps to Reproduce

  1. Run code from jsfiddle

Actual Behavior

The selection seems to be collapsed at end in some regards, but it doesn't show that. The value that was loaded initially is also showing, but is part of the undo history so that a CTRL+Z makes it go entirely, leaving the field blank.

Expected Behavior

  • There should be a way to collapse the selection to the end, also visually.

  • The initial value should not be "undoable"

Environment

Is this a regression: did it use to work in a previous version?

Not sure

MathLive version 0.95.5 (current)

Operating System: Ubuntu 23.04

Browser: Happens in Chrome and Firefox. Likely universal.

@arnog arnog closed this as completed in 3ff2f06 Dec 1, 2023
@arnog
Copy link
Owner

arnog commented Dec 1, 2023

There were several subtle problems in MathLive, but your code also doesn't do quite what you're looking for:

  • the select() function selects the content of the mathfield. I think you meant to use mf.focus() instead.
  • The content of mathfield.selection is essentially readonly. Modifying it will not result in the desired outcome.
  • To set the selection at the end of the mathfield, you can set the mf.position to -1

So, what you want is:

mathField.position = -1;
mathField.focus();

You could also set the selection to -1. The difference between the selection and the position is that the selection is a range (it has a start and an end), while the position is a single offset. However, if you set the selection to a single offset, it is automatically interpreted as a position instead, so in this case the two are synonymous.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants