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

incorrect cursor position for bold math text #4750

Closed
minrk opened this issue May 16, 2017 · 4 comments
Closed

incorrect cursor position for bold math text #4750

minrk opened this issue May 16, 2017 · 4 comments

Comments

@minrk
Copy link
Contributor

minrk commented May 16, 2017

Bold math text, such as 𝐚 (MATHEMATICAL BOLD SMALL A (U+1D41A), takes up two characters in cursor calculations, but is only one character.

Can be verified by inputting 𝐚 into any CodeMirror demo and calling editor.getCursor(). Appears to be related to #1813, possibly just another codepoint range to be added somewhere.

Reported downstream at JuliaLang/IJulia.jl#541 , jupyter/jupyter_client#259

@marijnh
Copy link
Member

marijnh commented May 16, 2017

Is the problem that such a character 'counts' as two characters in string offsets? If so, that's intentional -- JavaScript (unfortunately) represents strings as UTF-16, so 'astral plane' characers like this take up two string indices, and short of writing our own string representation, there's not much JavaScript libraries can do about that.

@stevengj
Copy link

stevengj commented May 16, 2017

Yes, 𝐚 is in an astral plane (U+01d41a), and it appears that CodeMirror is using 16-byte UTF-16 code units (not Unicode characters) for cursor calculations, since this is how JavaScript indexes strings. Unrelated to #1813 (combining characters, not surrogate pairs).

Probably Jupyter needs to convert this to/from Unicode character counts itself (so that it has an encoding-independent index).

@minrk
Copy link
Contributor Author

minrk commented May 20, 2017

Thanks, CodeMirror's behavior matching underlying js details makes sense. Adding the workaround in Jupyter: jupyter/notebook#2509

@oeddyo
Copy link

oeddyo commented Feb 18, 2021

@minrk this literally saved my life. Thanks!

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

4 participants