diff --git a/docs/reference/models/transform.md b/docs/reference/models/transform.md index 2aa8a21c9..c806731f2 100644 --- a/docs/reference/models/transform.md +++ b/docs/reference/models/transform.md @@ -29,17 +29,17 @@ Transform methods can either operate on the [`Document`](./document.md), the [`S - [`wrapInline`](#wrapinline) - [Selection Transforms](#selection-transforms) - [`blur`](#blur) - - [`extend{Direction}`](#extenddirection) + - [`collapseTo{Edge}Of`](#collapsetoedgeof) + - [`collapseTo{Edge}Of{Direction}Block`](#collapsetoedgeofdirectionblock) + - [`collapseTo{Edge}Of{Direction}Text`](#collapsetoedgeofdirectiontext) + - [`collapseTo{Edge}`](#collapsetoedge) - [`extendTo{Edge}Of`](#extendtoedgeof) + - [`extend{Direction}`](#extenddirection) - [`focus`](#focus) - - [`move{Direction}`](#movedirection) - [`moveToOffsets`](#movetooffsets) - [`moveToRangeOf`](#movetorangeof) - [`moveTo`](#moveto) - - [`moveTo{Edge}`](#movetoedge) - - [`moveTo{Edge}Of`](#movetoedgeof) - - [`moveTo{Edge}Of{Direction}Block`](#movetoedgeofdirectionblock) - - [`moveTo{Edge}Of{Direction}Text`](#movetoedgeofdirectiontext) + - [`move{Direction}`](#movedirection) - [Document Transforms](#document-transforms) - [`deleteAtRange`](#deleteatrange) - [`deleteBackwardAtRange`](#deletebackwardatrange) @@ -152,6 +152,26 @@ Wrap the [`Inline`](./inline.md) nodes in the current selection with a new [`Inl Blur the current selection. +### `collapseTo{Edge}` +`collapseTo{Edge}() => Transform` + +Collapse the current selection to its `{Edge}`. Where `{Edge}` is either `Anchor`, `Focus`, `Start` or `End`. + +### `collapseTo{Edge}Of` +`collapseTo{Edge}Of(node: Node) => Transform` + +Collapse the current selection to the `{Edge}` of `node`. Where `{Edge}` is either `Start` or `End`. + +### `collapseTo{Edge}Of{Direction}Block` +`collapseTo{Edge}Of{Direction}Block() => Transform` + +Collapse the current selection to the `{Edge}` of the next [`Block`](./block.md) node in `{Direction}`. Where `{Edge}` is either `{Start}` or `{End}` and `{Direction}` is either `Next` or `Previous`. + +### `collapseTo{Edge}Of{Direction}Text` +`collapseTo{Edge}Of{Direction}Text() => Transform` + +Collapse the current selection to the `{Edge}` of the next [`Text`](./text.md) node in `{Direction}`. Where `{Edge}` is either `{Start}` or `{End}` and `{Direction}` is either `Next` or `Previous`. + ### `extend{Direction}` `extend{Direction}(n: Number) => Transform` @@ -187,26 +207,6 @@ Move the current selection's anchor point to the start of a `node` and its focus Move the current selection to a selection with merged `properties`. -### `collapseTo{Edge}` -`collapseTo{Edge}() => Transform` - -Collapse the current selection to its `{Edge}`. Where `{Edge}` is either `Anchor`, `Focus`, `Start` or `End`. - -### `collapseTo{Edge}Of` -`collapseTo{Edge}Of(node: Node) => Transform` - -Collapse the current selection to the `{Edge}` of `node`. Where `{Edge}` is either `Start` or `End`. - -### `collapseTo{Edge}Of{Direction}Block` -`collapseTo{Edge}Of{Direction}Block() => Transform` - -Collapse the current selection to the `{Edge}` of the next [`Block`](./block.md) node in `{Direction}`. Where `{Edge}` is either `{Start}` or `{End}` and `{Direction}` is either `Next` or `Previous`. - -### `collapseTo{Edge}Of{Direction}Text` -`collapseTo{Edge}Of{Direction}Text() => Transform` - -Collapse the current selection to the `{Edge}` of the next [`Text`](./text.md) node in `{Direction}`. Where `{Edge}` is either `{Start}` or `{End}` and `{Direction}` is either `Next` or `Previous`. - ## Document Transforms diff --git a/examples/images/index.js b/examples/images/index.js index 15f25debf..af91c824d 100644 --- a/examples/images/index.js +++ b/examples/images/index.js @@ -142,11 +142,21 @@ class Images extends React.Component { if (anchorBlock.text != '') { if (selection.isAtEndOf(anchorBlock)) { - transform = transform.splitBlock() - } else if (selection.isAtStartOf(anchorBlock)) { - transform = transform.splitBlock().moveToStartOfPreviousBlock() - } else { - transform = transform.splitBlock().splitBlock().moveToStartOfPreviousBlock() + transform = transform + .splitBlock() + } + + else if (selection.isAtStartOf(anchorBlock)) { + transform = transform + .splitBlock() + .collapseToStartOfPreviousBlock() + } + + else { + transform = transform + .splitBlock() + .splitBlock() + .collapseToStartOfPreviousBlock() } } diff --git a/examples/links/index.js b/examples/links/index.js index e30dc0ad2..35ea95639 100644 --- a/examples/links/index.js +++ b/examples/links/index.js @@ -78,7 +78,7 @@ class Links extends React.Component { .insertText(text) .extendBackward(text.length) .wrapInline('link', new Map({ href })) - .moveToEnd(text.length) + .collapseToEnd() .apply() } diff --git a/lib/models/selection.js b/lib/models/selection.js index a969ccbd4..08eea254e 100644 --- a/lib/models/selection.js +++ b/lib/models/selection.js @@ -6,7 +6,7 @@ import { Record } from 'immutable' */ const START_END_METHODS = [ - 'moveTo%' + 'collapseTo%' ] /** diff --git a/lib/models/transform.js b/lib/models/transform.js index f59df2c62..ad70f6509 100644 --- a/lib/models/transform.js +++ b/lib/models/transform.js @@ -50,6 +50,12 @@ const DOCUMENT_TRANSFORMS = [ const SELECTION_TRANSFORMS = [ 'blur', + 'collapseToAnchor', + 'collapseToEnd', + 'collapseToEndOf', + 'collapseToFocus', + 'collapseToStart', + 'collapseToStartOf', 'extendBackward', 'extendForward', 'extendToEndOf', @@ -57,14 +63,8 @@ const SELECTION_TRANSFORMS = [ 'focus', 'moveBackward', 'moveForward', - 'collapseToAnchor', - 'collapseToEnd', - 'collapseToEndOf', - 'collapseToFocus', 'moveToOffsets', - 'moveToRangeOf', - 'collapseToStart', - 'collapseToStartOf' + 'moveToRangeOf' ] /** @@ -72,6 +72,14 @@ const SELECTION_TRANSFORMS = [ */ const STATE_TRANSFORMS = [ + 'collapseToEndOfNextBlock', + 'collapseToEndOfNextText', + 'collapseToEndOfPreviousBlock', + 'collapseToEndOfPreviousText', + 'collapseToStartOfNextBlock', + 'collapseToStartOfNextText', + 'collapseToStartOfPreviousBlock', + 'collapseToStartOfPreviousText', 'delete', 'deleteBackward', 'deleteForward', @@ -79,14 +87,6 @@ const STATE_TRANSFORMS = [ 'insertText', 'mark', 'moveTo', - 'collapseToStartOfPreviousBlock', - 'collapseToEndOfPreviousBlock', - 'collapseToStartOfNextBlock', - 'collapseToEndOfNextBlock', - 'collapseToStartOfPreviousText', - 'collapseToEndOfPreviousText', - 'collapseToStartOfNextText', - 'collapseToEndOfNextText', 'setBlock', 'setInline', 'splitBlock',