From a8c08a4e0107bccfe972149a512643fbbfcfb9bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E8=80=80=E8=80=80?= Date: Thu, 13 Jan 2022 21:24:36 +0800 Subject: [PATCH] Android merge `Editor.insertText` logic. (#4788) * fix: Android merge Editor.insertText logic * feat: add changeset --- .changeset/witty-moose-join.md | 5 +++++ .../src/components/android/android-editable.tsx | 16 +++------------- .../components/android/android-input-manager.ts | 16 +++------------- 3 files changed, 11 insertions(+), 26 deletions(-) create mode 100644 .changeset/witty-moose-join.md diff --git a/.changeset/witty-moose-join.md b/.changeset/witty-moose-join.md new file mode 100644 index 000000000..2e9069f95 --- /dev/null +++ b/.changeset/witty-moose-join.md @@ -0,0 +1,5 @@ +--- +'slate-react': patch +--- + +Android merge `Editor.insertText` logic. diff --git a/packages/slate-react/src/components/android/android-editable.tsx b/packages/slate-react/src/components/android/android-editable.tsx index 3a85eafc3..9761b4265 100644 --- a/packages/slate-react/src/components/android/android-editable.tsx +++ b/packages/slate-react/src/components/android/android-editable.tsx @@ -542,7 +542,7 @@ export const AndroidEditable = (props: EditableProps): JSX.Element => { EDITOR_ON_COMPOSITION_TEXT.set(editor, []) - const { selection, marks } = editor + const { selection } = editor insertedText.forEach(insertion => { const text = insertion.text.insertText @@ -551,18 +551,8 @@ export const AndroidEditable = (props: EditableProps): JSX.Element => { selection, insertion ) - if (marks) { - const node = { text, ...marks } - Transforms.insertNodes(editor, node, { - match: Text.isText, - at, - select: true, - }) - editor.marks = null - } else { - Transforms.setSelection(editor, at) - Editor.insertText(editor, text) - } + Transforms.setSelection(editor, at) + Editor.insertText(editor, text) }) }, RESOLVE_DELAY) } diff --git a/packages/slate-react/src/components/android/android-input-manager.ts b/packages/slate-react/src/components/android/android-input-manager.ts index 6521240b9..e9fe4fff7 100644 --- a/packages/slate-react/src/components/android/android-input-manager.ts +++ b/packages/slate-react/src/components/android/android-input-manager.ts @@ -108,7 +108,7 @@ export class AndroidInputManager { private insertText = (insertedText: TextInsertion[]) => { debug('insertText') - const { selection, marks } = this.editor + const { selection } = this.editor // If it is in composing or after `onCompositionend`, set `EDITOR_ON_COMPOSITION_TEXT` and return. // Text will be inserted on compositionend event. @@ -125,18 +125,8 @@ export class AndroidInputManager { insertedText.forEach(insertion => { const text = insertion.text.insertText const at = normalizeTextInsertionRange(this.editor, selection, insertion) - if (marks) { - const node = { text, ...marks } - Transforms.insertNodes(this.editor, node, { - match: Text.isText, - at, - select: true, - }) - this.editor.marks = null - } else { - Transforms.setSelection(this.editor, at) - Editor.insertText(this.editor, text) - } + Transforms.setSelection(this.editor, at) + Editor.insertText(this.editor, text) }) }