1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-21 14:41:23 +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:
Victor Pontis
2017-02-28 19:03:12 -08:00
committed by Ian Storm Taylor
parent d426874b57
commit 77f939d6c8
3 changed files with 57 additions and 0 deletions

View File

@@ -20,6 +20,22 @@ Transforms.select = (transform, properties) => {
transform.setSelectionOperation(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. * Snapshot the current selection.
* *

View File

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

View File

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