mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-26 08:34:28 +02:00
finish refactoring selection transforms
This commit is contained in:
@@ -62,8 +62,8 @@ export function collapseToEndOf(transform, node) {
|
||||
/**
|
||||
* Move the selection to the end of the next block.
|
||||
*
|
||||
* @param {State} state
|
||||
* @return {State}
|
||||
* @param {Transform} tansform
|
||||
* @return {Transform}
|
||||
*/
|
||||
|
||||
export function collapseToEndOfNextBlock(transform) {
|
||||
@@ -81,8 +81,8 @@ export function collapseToEndOfNextBlock(transform) {
|
||||
/**
|
||||
* Move the selection to the end of the next text.
|
||||
*
|
||||
* @param {State} state
|
||||
* @return {State}
|
||||
* @param {Transform} tansform
|
||||
* @return {Transform}
|
||||
*/
|
||||
|
||||
export function collapseToEndOfNextText(transform) {
|
||||
@@ -100,8 +100,8 @@ export function collapseToEndOfNextText(transform) {
|
||||
/**
|
||||
* Move the selection to the end of the previous block.
|
||||
*
|
||||
* @param {State} state
|
||||
* @return {State}
|
||||
* @param {Transform} tansform
|
||||
* @return {Transform}
|
||||
*/
|
||||
|
||||
export function collapseToEndOfPreviousBlock(transform) {
|
||||
@@ -119,8 +119,8 @@ export function collapseToEndOfPreviousBlock(transform) {
|
||||
/**
|
||||
* Move the selection to the end of the previous text.
|
||||
*
|
||||
* @param {State} state
|
||||
* @return {State}
|
||||
* @param {Transform} tansform
|
||||
* @return {Transform}
|
||||
*/
|
||||
|
||||
export function collapseToEndOfPreviousText(transform) {
|
||||
@@ -136,9 +136,10 @@ export function collapseToEndOfPreviousText(transform) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Move to the start of a `node
|
||||
* `.
|
||||
* Move to the start of a `node`.
|
||||
*
|
||||
* @param {Transform} transform
|
||||
* @param {Node} node
|
||||
* @return {Transform}
|
||||
*/
|
||||
|
||||
@@ -152,8 +153,8 @@ export function collapseToStartOf(transform, node) {
|
||||
/**
|
||||
* Move the selection to the start of the next block.
|
||||
*
|
||||
* @param {State} state
|
||||
* @return {State}
|
||||
* @param {Transform} tansform
|
||||
* @return {Transform}
|
||||
*/
|
||||
|
||||
export function collapseToStartOfNextBlock(transform) {
|
||||
@@ -171,8 +172,8 @@ export function collapseToStartOfNextBlock(transform) {
|
||||
/**
|
||||
* Move the selection to the start of the next text.
|
||||
*
|
||||
* @param {State} state
|
||||
* @return {State}
|
||||
* @param {Transform} tansform
|
||||
* @return {Transform}
|
||||
*/
|
||||
|
||||
export function collapseToStartOfNextText(transform) {
|
||||
@@ -190,8 +191,8 @@ export function collapseToStartOfNextText(transform) {
|
||||
/**
|
||||
* Move the selection to the start of the previous block.
|
||||
*
|
||||
* @param {State} state
|
||||
* @return {State}
|
||||
* @param {Transform} tansform
|
||||
* @return {Transform}
|
||||
*/
|
||||
|
||||
export function collapseToStartOfPreviousBlock(transform) {
|
||||
@@ -209,8 +210,8 @@ export function collapseToStartOfPreviousBlock(transform) {
|
||||
/**
|
||||
* Move the selection to the start of the previous text.
|
||||
*
|
||||
* @param {State} state
|
||||
* @return {State}
|
||||
* @param {Transform} tansform
|
||||
* @return {Transform}
|
||||
*/
|
||||
|
||||
export function collapseToStartOfPreviousText(transform) {
|
||||
@@ -228,69 +229,61 @@ export function collapseToStartOfPreviousText(transform) {
|
||||
/**
|
||||
* Extend the focus point backward `n` characters.
|
||||
*
|
||||
* @param {Transform} transform
|
||||
* @param {Number} n (optional)
|
||||
* @return {Transform}
|
||||
*/
|
||||
|
||||
export function extendBackward(transform, ...args) {
|
||||
let { state } = transform
|
||||
let { document, selection } = state
|
||||
selection = selection.extendBackward(...args)
|
||||
selection = selection.normalize(document)
|
||||
state = state.merge({ selection })
|
||||
transform.state = state
|
||||
return transform
|
||||
export function extendBackward(transform, n) {
|
||||
const { state } = transform
|
||||
const { document, selection } = state
|
||||
const sel = selection.extendBackward(n).normalize(document)
|
||||
return transform.updateSelection(sel)
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend the focus point forward `n` characters.
|
||||
*
|
||||
* @param {Transform} transform
|
||||
* @param {Number} n (optional)
|
||||
* @return {Transform}
|
||||
*/
|
||||
|
||||
export function extendForward(transform, ...args) {
|
||||
let { state } = transform
|
||||
let { document, selection } = state
|
||||
selection = selection.extendForward(...args)
|
||||
selection = selection.normalize(document)
|
||||
state = state.merge({ selection })
|
||||
transform.state = state
|
||||
return transform
|
||||
export function extendForward(transform, n) {
|
||||
const { state } = transform
|
||||
const { document, selection } = state
|
||||
const sel = selection.extendForward(n).normalize(document)
|
||||
return transform.updateSelection(sel)
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend the focus point to the end of a `node`.
|
||||
*
|
||||
* @param {Transform} transform
|
||||
* @param {Node} node
|
||||
* @return {Transform}
|
||||
*/
|
||||
|
||||
export function extendToEndOf(transform, ...args) {
|
||||
let { state } = transform
|
||||
let { document, selection } = state
|
||||
selection = selection.extendToEndOf(...args)
|
||||
selection = selection.normalize(document)
|
||||
state = state.merge({ selection })
|
||||
transform.state = state
|
||||
return transform
|
||||
export function extendToEndOf(transform, node) {
|
||||
const { state } = transform
|
||||
const { document, selection } = state
|
||||
const sel = selection.extendToEndOf(node).normalize(document)
|
||||
return transform.updateSelection(sel)
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend the focus point to the start of a `node`.
|
||||
*
|
||||
* @param {Transform} transform
|
||||
* @param {Node} node
|
||||
* @return {Transform}
|
||||
*/
|
||||
|
||||
export function extendToStartOf(transform, ...args) {
|
||||
let { state } = transform
|
||||
let { document, selection } = state
|
||||
selection = selection.extendToStartOf(...args)
|
||||
selection = selection.normalize(document)
|
||||
state = state.merge({ selection })
|
||||
transform.state = state
|
||||
return transform
|
||||
export function extendToStartOf(transform, node) {
|
||||
const { state } = transform
|
||||
const { document, selection } = state
|
||||
const sel = selection.extendToStartOf(node).normalize(document)
|
||||
return transform.updateSelection(sel)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -300,119 +293,89 @@ export function extendToStartOf(transform, ...args) {
|
||||
* @return {Transform}
|
||||
*/
|
||||
|
||||
export function focus(transform, ...args) {
|
||||
let { state } = transform
|
||||
let { document, selection } = state
|
||||
selection = selection.focus(...args)
|
||||
selection = selection.normalize(document)
|
||||
state = state.merge({ selection })
|
||||
transform.state = state
|
||||
return transform
|
||||
export function focus(transform) {
|
||||
const { state } = transform
|
||||
const { selection } = state
|
||||
const sel = selection.focus()
|
||||
return transform.updateSelection(sel)
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the selection backward `n` characters.
|
||||
*
|
||||
* @param {Transform} transform
|
||||
* @param {Number} n (optional)
|
||||
* @return {Transform}
|
||||
*/
|
||||
|
||||
export function moveBackward(transform, ...args) {
|
||||
let { state } = transform
|
||||
let { document, selection } = state
|
||||
selection = selection.moveBackward(...args)
|
||||
selection = selection.normalize(document)
|
||||
state = state.merge({ selection })
|
||||
transform.state = state
|
||||
return transform
|
||||
export function moveBackward(transform, n) {
|
||||
const { state } = transform
|
||||
const { document, selection } = state
|
||||
const sel = selection.moveBackward(n).normalize(document)
|
||||
return transform.updateSelection(sel)
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the selection forward `n` characters.
|
||||
*
|
||||
* @param {Transform} transform
|
||||
* @param {Number} n (optional)
|
||||
* @return {Transform}
|
||||
*/
|
||||
|
||||
export function moveForward(transform, ...args) {
|
||||
let { state } = transform
|
||||
let { document, selection } = state
|
||||
selection = selection.moveForward(...args)
|
||||
selection = selection.normalize(document)
|
||||
state = state.merge({ selection })
|
||||
transform.state = state
|
||||
return transform
|
||||
export function moveForward(transform, n) {
|
||||
const { state } = transform
|
||||
const { document, selection } = state
|
||||
const sel = selection.moveForward(n).normalize(document)
|
||||
return transform.updateSelection(sel)
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the selection to a specific anchor and focus point.
|
||||
*
|
||||
* @param {State} state
|
||||
* @param {Transform} transform
|
||||
* @param {Object} properties
|
||||
* @return {State}
|
||||
* @return {Transform}
|
||||
*/
|
||||
|
||||
export function moveTo(transform, properties) {
|
||||
let { state } = transform
|
||||
let { document, selection } = state
|
||||
|
||||
// Allow for passing a `Selection` object.
|
||||
if (properties instanceof Selection) {
|
||||
properties = {
|
||||
anchorKey: properties.anchorKey,
|
||||
anchorOffset: properties.anchorOffset,
|
||||
focusKey: properties.focusKey,
|
||||
focusOffset: properties.focusOffset,
|
||||
isFocused: properties.isFocused
|
||||
}
|
||||
}
|
||||
|
||||
// Pass in properties, and force `isBackward` to be re-resolved.
|
||||
selection = selection.merge({
|
||||
...properties,
|
||||
isBackward: null
|
||||
})
|
||||
|
||||
selection = selection.normalize(document)
|
||||
state = state.merge({ selection })
|
||||
transform.state = state
|
||||
return transform
|
||||
properties = Normalize.selection(properties)
|
||||
const { state } = transform
|
||||
const { document, selection } = state
|
||||
const sel = selection.merge(properties).normalize(document)
|
||||
return transform.updateSelection(sel)
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the selection to `anchor` and `focus` offsets.
|
||||
*
|
||||
* @param {Transform} transform
|
||||
* @param {Number} anchor
|
||||
* @param {Number} focus (optional)
|
||||
* @return {Transform}
|
||||
*/
|
||||
|
||||
export function moveToOffsets(transform, ...args) {
|
||||
let { state } = transform
|
||||
let { document, selection } = state
|
||||
selection = selection.moveToOffsets(...args)
|
||||
selection = selection.normalize(document)
|
||||
state = state.merge({ selection })
|
||||
transform.state = state
|
||||
return transform
|
||||
export function moveToOffsets(transform, anchor, fokus) {
|
||||
const { state } = transform
|
||||
const { document, selection } = state
|
||||
const sel = selection.moveToOffsets(anchor, fokus)
|
||||
return transform.updateSelection(sel)
|
||||
}
|
||||
|
||||
/**
|
||||
* Move to the entire range of `start` and `end` nodes.
|
||||
*
|
||||
* @param {Transform} transform
|
||||
* @param {Node} start
|
||||
* @param {Node} end (optional)
|
||||
* @return {Transform}
|
||||
*/
|
||||
|
||||
export function moveToRangeOf(transform, ...args) {
|
||||
let { state } = transform
|
||||
let { document, selection } = state
|
||||
selection = selection.moveToRangeOf(...args)
|
||||
selection = selection.normalize(document)
|
||||
state = state.merge({ selection })
|
||||
transform.state = state
|
||||
return transform
|
||||
export function moveToRangeOf(transform, start, end) {
|
||||
const { state } = transform
|
||||
const { document, selection } = state
|
||||
const sel = selection.moveToRangeOf(start, end).normalize(document)
|
||||
return transform.updateSelection(sel)
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user