1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-27 09:04:31 +02:00

update insertText logic when selection is not collapsed (#4892)

Co-authored-by: zhangpengcheng15 <zhangpengcheng15@jd.com>
This commit is contained in:
V_Lute
2022-05-07 21:14:01 +08:00
committed by GitHub
parent 1555ac8402
commit d2fc25c3c3
3 changed files with 47 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
'slate': minor
---
update insertText logic when selection is not collapsed

View File

@@ -474,9 +474,14 @@ export const TextTransforms: TextTransforms = {
if (!voids && Editor.void(editor, { at: end })) {
return
}
const pointRef = Editor.pointRef(editor, end)
const start = Range.start(at)
const startRef = Editor.pointRef(editor, start)
const endRef = Editor.pointRef(editor, end)
Transforms.delete(editor, { at, voids })
at = pointRef.unref()!
const startPoint = startRef.unref()
const endPoint = endRef.unref()
at = startPoint || endPoint!
Transforms.setSelection(editor, { anchor: at, focus: at })
}
}

View File

@@ -0,0 +1,35 @@
/** @jsx jsx */
import { Transforms } from 'slate'
import { jsx } from '../../..'
export const run = editor => {
Transforms.insertText(editor, 'a')
}
export const input = (
<editor>
<block>
first paragraph
<inline>
tw
<anchor />o
</inline>
</block>
<block>
second
<focus />
paragraph
</block>
</editor>
)
export const output = (
<editor>
<block>
first paragraph
<inline>
twa
<cursor />
</inline>
paragraph
</block>
</editor>
)