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:
5
.changeset/wise-dots-cheat.md
Normal file
5
.changeset/wise-dots-cheat.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'slate': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
update insertText logic when selection is not collapsed
|
@@ -474,9 +474,14 @@ export const TextTransforms: TextTransforms = {
|
|||||||
if (!voids && Editor.void(editor, { at: end })) {
|
if (!voids && Editor.void(editor, { at: end })) {
|
||||||
return
|
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 })
|
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 })
|
Transforms.setSelection(editor, { anchor: at, focus: at })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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>
|
||||||
|
)
|
Reference in New Issue
Block a user