-
Notifications
You must be signed in to change notification settings - Fork 30
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
Fix cursor on emojis #49
Conversation
nightwing
commented
Aug 17, 2022
- fixes cursor displaying � when placed over emoji
- fixes a bug of vim placing cursor inside emojis and other surrogate pairs
- fixes cursor bug described in the following comment Cursor moves past end of line in vim #38 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤗 cursor looks great! couple of nits and questions. (one thing I found is pressing x
doesn't delete the whole emoji character but it should be fine for the scope of this PR as it happens before the change)
tagging @sergeichestakov for additional (but optional) 👀 as I don't have a lot of context.
src/block-cursor.ts
Outdated
node = node.parentNode; | ||
} | ||
let style = getComputedStyle(node as HTMLElement); | ||
let letter = head < view.state.doc.length && view.state.sliceDoc(head, head + 1); | ||
if (!letter || letter == "\n" || letter == "\r") letter = "\xa0"; | ||
else if ((/[\uD800-\uDC00]/.test(letter) && head < view.state.doc.length - 1)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add surrogate pair comment here too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reading the doc here, high surrogate ranges from U+D800 to U+DBFF. should this include \uDC00
?
src/vim.js
Outdated
var ch = Math.min(Math.max(0, cur.ch), maxCh); | ||
// prevent cursor from entering surrogate pair | ||
var charCode = text.charCodeAt(ch); | ||
if (0xDC00 < charCode && charCode <0xDFFF) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar question to above, low surrogate ranges from U+DC00 to U+DFFF. should this range be inclusive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are right, it should be.
} | ||
} | ||
ch +=direction; | ||
if (ch > maxCh) ch -=2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does ch -= 2
do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when cursor is moved from left side into surrogate pair the code above attempts to go to the left, as a result we may end up outside the line, in which case we have to step back
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks yeah please resolve @xyc's comments. Otherwise, looks good to me
a325e05
to
34d35c1
Compare
Co-authored-by: Xiaoyi Chen <[email protected]>
34d35c1
to
d09f539
Compare