mathewthe2 / immersion_reader

iOS Reader with Japanese popup dictionary
MIT License
27 stars 1 forks source link

Improve text selection reliability #7

Closed mathewthe2 closed 1 year ago

mathewthe2 commented 1 year ago

Issue

Text selection is unreliable

Reason

Selection relies on caretRangeFromPoint and range.startOffset, which selects the next character when the cursor selects around 70% of the previous character.

https://github.com/birchill/10ten-ja-reader/blob/fbbbde5c429f1467a7b5a938e9d67597d7bd5ffa/src/content/get-text.ts#L248

Suggestion

Adjust position by getting the bounding box of the previous character and see if point is within that bounding box. If yes, use previous character.

mathewthe2 commented 1 year ago

Related issue https://github.com/lrorpilla/jidoujisho/issues/133

arianneorpilla commented 1 year ago

Hey @mathewthe2, thanks for pointing this out to me.

I've modified the JavaScript I inject accordingly with the reference you posted above here and it appears to work on Chrome in various font sizes.