Skip to content

fix(Field): cursor position is not placed right while emoji is inputed #13369

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/vant/src/field/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,7 @@ export default defineComponent({
// When the value length exceeds maxlength,
// record the excess length for correcting the cursor position.
// https://github.com/youzan/vant/issues/11289
const limitDiffLen =
getStringLength(originalValue) - getStringLength(value);
const limitDiffLen = originalValue.length - value.length;

// https://github.com/youzan/vant/issues/13058
if (props.type === 'number' || props.type === 'digit') {
Expand Down Expand Up @@ -379,7 +378,7 @@ export default defineComponent({
inputRef.value.value = value;

if (isDef(selectionStart) && isDef(selectionEnd)) {
const valueLen = getStringLength(value);
const valueLen = value.length;

if (limitDiffLen) {
selectionStart -= limitDiffLen;
Expand Down