1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-04-15 10:52:34 +02:00

Android merge Editor.insertText logic. (#4788)

* fix: Android merge Editor.insertText logic

* feat: add changeset
This commit is contained in:
陈耀耀 2022-01-13 21:24:36 +08:00 committed by GitHub
parent 67aa1f1010
commit a8c08a4e01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 26 deletions

View File

@ -0,0 +1,5 @@
---
'slate-react': patch
---
Android merge `Editor.insertText` logic.

View File

@ -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)
}

View File

@ -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)
})
}