Browse Source
Merge pull request #191 from wangeditor-team/fix-composition
fix: 修复选中内容中文输入时光标定位问题
fix-react18
王福朋
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
5 additions and
3 deletions
-
packages/core/src/text-area/event-handlers/composition.ts
|
|
@ -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 时使用
|
|
|
@ -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
|
|
|
|