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

Fix cursor on emojis #49

Merged
merged 3 commits into from
Oct 19, 2022
Merged

Fix cursor on emojis #49

merged 3 commits into from
Oct 19, 2022

Conversation

nightwing
Copy link
Collaborator

Copy link
Contributor

@xyc xyc left a 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.

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)) {
Copy link
Contributor

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?

Copy link
Contributor

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) {
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

src/vim.js Outdated Show resolved Hide resolved
}
}
ch +=direction;
if (ch > maxCh) ch -=2;
Copy link
Contributor

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?

Copy link
Collaborator Author

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

src/vim.js Outdated Show resolved Hide resolved
Copy link
Contributor

@sergeichestakov sergeichestakov left a 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

Co-authored-by: Xiaoyi Chen <cxychina@gmail.com>
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

Successfully merging this pull request may close these issues.

None yet

3 participants