1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-04-21 22:02:05 +02:00

fix undoing removing text with marks, closes #350

This commit is contained in:
Ian Storm Taylor 2016-11-21 14:36:41 -08:00
parent f4d6efd0e7
commit 7cd64deb0c
4 changed files with 71 additions and 3 deletions

View File

@ -250,14 +250,18 @@ export function removeTextOperation(transform, path, offset, length) {
const ranges = node.getRanges()
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) => {
const { text, marks } = range
const end = start + text.length
if (start > offset + length) return
if (end <= offset) return
if (start > offset + length) return end
if (end <= offset) return end
const endOffset = Math.min(end, offset + length)
const string = text.slice(offset, endOffset)
const string = text.slice(offset - start, endOffset - start)
inverse.push({
type: 'insert_text',

View File

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

View File

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

View File

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