From 834ce3483dc407a6293ba29cac8f192c13f57b01 Mon Sep 17 00:00:00 2001 From: I Made Budi Surya Darma Date: Fri, 13 Aug 2021 18:55:27 +0800 Subject: [PATCH] fix(android): Fix editors mark is not inserted on insert text in android (#4342) * fix(android): Fix mark is not inputed on insert text in android * add changeset * null mark only when mark exist Co-authored-by: surya darma --- .changeset/thick-geckos-kick.md | 5 +++++ .../android/android-input-manager.ts | 22 ++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 .changeset/thick-geckos-kick.md diff --git a/.changeset/thick-geckos-kick.md b/.changeset/thick-geckos-kick.md new file mode 100644 index 000000000..369a13a11 --- /dev/null +++ b/.changeset/thick-geckos-kick.md @@ -0,0 +1,5 @@ +--- +'slate-react': patch +--- + +Fix editor mark is not inserted on android 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 87d81d972..3e4c751de 100644 --- a/packages/slate-react/src/components/android/android-input-manager.ts +++ b/packages/slate-react/src/components/android/android-input-manager.ts @@ -1,5 +1,5 @@ import { ReactEditor } from '../../plugin/react-editor' -import { Editor, Range, Transforms } from 'slate' +import { Editor, Range, Transforms, Text } from 'slate' import { DOMNode } from '../../utils/dom' @@ -102,13 +102,25 @@ export class AndroidInputManager { private insertText = (insertedText: TextInsertion[]) => { debug('insertText') - const { selection } = this.editor + const { selection, marks } = this.editor // Insert the batched text diffs insertedText.forEach(insertion => { - Transforms.insertText(this.editor, insertion.text.insertText, { - at: normalizeTextInsertionRange(this.editor, selection, 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.insertText(this.editor, text, { + at, + }) + } }) }