mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-08 00:06:37 +02:00
fix undoing removing text with marks, closes #350
This commit is contained in:
@@ -250,14 +250,18 @@ export function removeTextOperation(transform, path, offset, length) {
|
|||||||
const ranges = node.getRanges()
|
const ranges = node.getRanges()
|
||||||
const inverse = []
|
const inverse = []
|
||||||
|
|
||||||
|
// Loop the ranges of text in the node, creating inverse insert operations for
|
||||||
|
// each of the ranges that overlap with the remove operation. This is
|
||||||
|
// necessary because insert's can only have a single set of marks associated
|
||||||
|
// with them, but removes can remove many.
|
||||||
ranges.reduce((start, range) => {
|
ranges.reduce((start, range) => {
|
||||||
const { text, marks } = range
|
const { text, marks } = range
|
||||||
const end = start + text.length
|
const end = start + text.length
|
||||||
if (start > offset + length) return
|
if (start > offset + length) return end
|
||||||
if (end <= offset) return
|
if (end <= offset) return end
|
||||||
|
|
||||||
const endOffset = Math.min(end, offset + length)
|
const endOffset = Math.min(end, offset + length)
|
||||||
const string = text.slice(offset, endOffset)
|
const string = text.slice(offset - start, endOffset - start)
|
||||||
|
|
||||||
inverse.push({
|
inverse.push({
|
||||||
type: 'insert_text',
|
type: 'insert_text',
|
||||||
|
@@ -0,0 +1,26 @@
|
|||||||
|
|
||||||
|
import assert from 'assert'
|
||||||
|
|
||||||
|
export default function (state) {
|
||||||
|
const { document, selection } = state
|
||||||
|
const texts = document.getTexts()
|
||||||
|
const first = texts.first()
|
||||||
|
|
||||||
|
const next = state
|
||||||
|
.transform()
|
||||||
|
.moveTo({
|
||||||
|
anchorKey: first.key,
|
||||||
|
anchorOffset: 10,
|
||||||
|
focusKey: first.key,
|
||||||
|
focusOffset: 10
|
||||||
|
})
|
||||||
|
.deleteBackward()
|
||||||
|
.apply()
|
||||||
|
|
||||||
|
.transform()
|
||||||
|
.undo()
|
||||||
|
.apply()
|
||||||
|
|
||||||
|
assert.deepEqual(next.selection.toJS(), selection.toJS())
|
||||||
|
return next
|
||||||
|
}
|
@@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
nodes:
|
||||||
|
- kind: block
|
||||||
|
type: paragraph
|
||||||
|
nodes:
|
||||||
|
- kind: text
|
||||||
|
ranges:
|
||||||
|
- text: one
|
||||||
|
marks:
|
||||||
|
- type: bold
|
||||||
|
- text: two
|
||||||
|
marks:
|
||||||
|
- type: underlined
|
||||||
|
- text: three
|
||||||
|
marks:
|
||||||
|
- type: italic
|
||||||
|
- text: four
|
||||||
|
marks:
|
||||||
|
- type: bold
|
@@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
nodes:
|
||||||
|
- kind: block
|
||||||
|
type: paragraph
|
||||||
|
nodes:
|
||||||
|
- kind: text
|
||||||
|
ranges:
|
||||||
|
- text: one
|
||||||
|
marks:
|
||||||
|
- type: bold
|
||||||
|
- text: two
|
||||||
|
marks:
|
||||||
|
- type: underlined
|
||||||
|
- text: three
|
||||||
|
marks:
|
||||||
|
- type: italic
|
||||||
|
- text: four
|
||||||
|
marks:
|
||||||
|
- type: bold
|
Reference in New Issue
Block a user