diff --git a/src/transforms/on-selection.js b/src/transforms/on-selection.js index eb1f5b67d..ecbc15180 100644 --- a/src/transforms/on-selection.js +++ b/src/transforms/on-selection.js @@ -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. * diff --git a/test/transforms/fixtures/on-selection/select-all/basic/index.js b/test/transforms/fixtures/on-selection/select-all/basic/index.js new file mode 100644 index 000000000..df4b287ba --- /dev/null +++ b/test/transforms/fixtures/on-selection/select-all/basic/index.js @@ -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() + ) +} diff --git a/test/transforms/fixtures/on-selection/select-all/basic/input.yaml b/test/transforms/fixtures/on-selection/select-all/basic/input.yaml new file mode 100644 index 000000000..2a7e1afb1 --- /dev/null +++ b/test/transforms/fixtures/on-selection/select-all/basic/input.yaml @@ -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