mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-21 22:45:18 +02:00
Add functionality and test-case for selectAll (#637)
* Add functionality and test-case for selectAll * Update to use moveToRange
This commit is contained in:
committed by
Ian Storm Taylor
parent
d426874b57
commit
77f939d6c8
@@ -20,6 +20,22 @@ Transforms.select = (transform, properties) => {
|
||||
transform.setSelectionOperation(properties)
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the whole selection.
|
||||
*
|
||||
* @param {Transform} transform
|
||||
* @param {Object} properties
|
||||
*/
|
||||
|
||||
Transforms.selectAll = (transform) => {
|
||||
const { state } = transform
|
||||
const { document, selection } = state
|
||||
const next = selection
|
||||
.moveToRangeOf(document)
|
||||
.focus()
|
||||
transform.setSelectionOperation(next)
|
||||
}
|
||||
|
||||
/**
|
||||
* Snapshot the current selection.
|
||||
*
|
||||
|
@@ -0,0 +1,24 @@
|
||||
|
||||
import assert from 'assert'
|
||||
|
||||
export default function (state) {
|
||||
const { selection } = state
|
||||
|
||||
const next = state
|
||||
.transform()
|
||||
.selectAll(selection)
|
||||
.apply()
|
||||
|
||||
const sel = selection.merge({
|
||||
anchorKey: '0',
|
||||
anchorOffset: 0,
|
||||
focusKey: '4',
|
||||
focusOffset: 5,
|
||||
isFocused: true
|
||||
})
|
||||
|
||||
assert.deepEqual(
|
||||
next.selection.toJS(),
|
||||
sel.toJS()
|
||||
)
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
text: one
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
text: two
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
text: three
|
Reference in New Issue
Block a user