desmosinc / mathquill

Magic textboxes where you can type math as easily as writing!
mathquill.com
137 stars 42 forks source link

export selection #245

Closed mikehaverstock closed 2 years ago

mikehaverstock commented 2 years ago

Adds a .selection() method to get the current selection out of the mathquill instance. Will return something like:

{
   latex: '12345'
   startIndex: 2,
   endIndex: 3
}
mikehaverstock commented 2 years ago

I don't know why this test is failing. It's passing for me locally.

mikehaverstock commented 2 years ago

retest windows

jwmerrill commented 2 years ago

Just want to verify my understanding: we always have startIndex <= endIndex, right? So this API isn't giving information about the orientation of the selection?

I think that's probably a good call for the public API. Can't see a ton of reasons to care about selection orientation, and it'd likely trip people up who haven't thought about that before if we did represent it.

jwmerrill commented 2 years ago

Did you ever figure out where info is stored about whether the cursor is displayed in a MathQuill (or in other words, whether it has focus)? Could see that being useful to report here too, but maybe you can just get that some other way. Wouldn't be a breaking change to add it later.

mikehaverstock commented 2 years ago

startIndex <= endIndex

Yes. We don't keep orientation. startIndex can't be after endIndex.

mikehaverstock commented 2 years ago

Did you ever figure out where info is stored about whether the cursor is displayed in a MathQuill (or in other words, whether it has focus)? Could see that being useful to report here too, but maybe you can just get that some other way. Wouldn't be a breaking change to add it later.

No. In my use case I won't need it. The mq will always be focused when I ask this question. If there is a way to ask it explicitly then callers of this method can just call it. There are definitely cases where you can have a selection in an unfocsed mathquill. So it probably makes sense to not conflate focus with store dcursor/selection position.