1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-01 04:50:27 +02:00
This commit is contained in:
Ian Storm Taylor
2016-07-12 21:14:21 -07:00
parent c1db9675b2
commit 510eb63d8d
5 changed files with 58 additions and 48 deletions

View File

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

View File

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

View File

@@ -78,7 +78,7 @@ class Links extends React.Component {
.insertText(text)
.extendBackward(text.length)
.wrapInline('link', new Map({ href }))
.moveToEnd(text.length)
.collapseToEnd()
.apply()
}

View File

@@ -6,7 +6,7 @@ import { Record } from 'immutable'
*/
const START_END_METHODS = [
'moveTo%'
'collapseTo%'
]
/**

View File

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