1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-30 10:29:48 +02:00

fix deleting backward/forward multiple characters, fixes #326

This commit is contained in:
Ian Storm Taylor
2016-09-15 14:49:43 -07:00
parent 3951f89e0f
commit f27ccd5140
13 changed files with 146 additions and 2 deletions

View File

@@ -152,7 +152,7 @@ export function deleteBackwardAtRange(transform, range, n = 1) {
}
range = range.merge({
focusOffset: focusOffset - 1,
focusOffset: focusOffset - n,
isBackward: true,
})
@@ -204,7 +204,7 @@ export function deleteForwardAtRange(transform, range, n = 1) {
}
range = range.merge({
focusOffset: focusOffset + 1
focusOffset: focusOffset + n
})
return transform.deleteAtRange(range)

View File

@@ -0,0 +1,27 @@
import assert from 'assert'
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const first = texts.first()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: first.length,
focusKey: first.key,
focusOffset: first.length
})
const next = state
.transform()
.moveTo(range)
.deleteBackward(3)
.apply()
assert.deepEqual(
next.selection.toJS(),
range.moveBackward(3).toJS()
)
return next
}

View File

@@ -0,0 +1,7 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: word

View File

@@ -0,0 +1,7 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: w

View File

@@ -0,0 +1,27 @@
import assert from 'assert'
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const first = texts.first()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: 0,
focusKey: first.key,
focusOffset: 0
})
const next = state
.transform()
.moveTo(range)
.deleteForward(3)
.apply()
assert.deepEqual(
next.selection.toJS(),
range.collapseToStart().toJS()
)
return next
}

View File

@@ -0,0 +1,7 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: word

View File

@@ -0,0 +1,7 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: d

View File

@@ -0,0 +1,17 @@
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const first = texts.first()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: first.length,
focusKey: first.key,
focusOffset: first.length
})
return state
.transform()
.deleteBackwardAtRange(range, 3)
.apply()
}

View File

@@ -0,0 +1,7 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: word

View File

@@ -0,0 +1,7 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: w

View File

@@ -0,0 +1,17 @@
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const first = texts.first()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: 0,
focusKey: first.key,
focusOffset: 0
})
return state
.transform()
.deleteForwardAtRange(range, 3)
.apply()
}

View File

@@ -0,0 +1,7 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: word

View File

@@ -0,0 +1,7 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: d