Skip to content
This repository has been archived by the owner on Apr 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #191 from wangeditor-team/fix-composition
Browse files Browse the repository at this point in the history
fix: 修复选中内容中文输入时光标定位问题
  • Loading branch information
wangfupeng1988 authored Sep 7, 2021
2 parents a516f6b + 51596a8 commit 6714358
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/core/src/text-area/event-handlers/composition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ export function handleCompositionStart(e: Event, textarea: TextArea, editor: IDo
if (!hasEditableTarget(editor, event.target)) return

const { selection } = editor
if (selection && Range.isExpanded(selection)) {
Editor.deleteFragment(editor)
}

if (selection && Range.isCollapsed(selection)) {
// 记录下 dom text ,以便触发 maxLength 时使用
Expand Down Expand Up @@ -70,6 +67,11 @@ export function handleCompositionEnd(e: Event, textarea: TextArea, editor: IDomE
const { selection } = editor
if (selection == null) return

// 不能在 compositionStart 时删除,否则会导致 dom 更新,光标错位
if (selection && Range.isExpanded(selection)) {
Editor.deleteFragment(editor)
}

// 在中文输入法下,浏览器的默认行为会使一些dom产生不可逆的变化
// 比如在 Safari 中 url 后面输入,初始是 a > span > spans
// 输入后变成 span > span > a
Expand Down

0 comments on commit 6714358

Please sign in to comment.