mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-30 18:39:51 +02:00
fix moveToRangeOf, collapseToStart/EndOf
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
|
|
||||||
import getLeafText from '../utils/get-leaf-text'
|
|
||||||
import warn from '../utils/warn'
|
import warn from '../utils/warn'
|
||||||
import { Record } from 'immutable'
|
import { Record } from 'immutable'
|
||||||
|
|
||||||
@@ -417,8 +416,7 @@ class Selection extends new Record(DEFAULTS) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
collapseToStartOf(node) {
|
collapseToStartOf(node) {
|
||||||
node = getLeafText(node)
|
node = node.kind == 'text' ? node : node.getFirstText()
|
||||||
|
|
||||||
return this.merge({
|
return this.merge({
|
||||||
anchorKey: node.key,
|
anchorKey: node.key,
|
||||||
anchorOffset: 0,
|
anchorOffset: 0,
|
||||||
@@ -435,8 +433,7 @@ class Selection extends new Record(DEFAULTS) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
collapseToEndOf(node) {
|
collapseToEndOf(node) {
|
||||||
node = getLeafText(node)
|
node = node.kind == 'text' ? node : node.getLastText()
|
||||||
|
|
||||||
return this.merge({
|
return this.merge({
|
||||||
anchorKey: node.key,
|
anchorKey: node.key,
|
||||||
anchorOffset: node.length,
|
anchorOffset: node.length,
|
||||||
@@ -456,9 +453,8 @@ class Selection extends new Record(DEFAULTS) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
moveToRangeOf(start, end = start) {
|
moveToRangeOf(start, end = start) {
|
||||||
start = getLeafText(start)
|
start = start.kind == 'text' ? start : start.getFirstText()
|
||||||
end = getLeafText(end)
|
end = end.kind == 'text' ? end : end.getLastText()
|
||||||
|
|
||||||
return this.merge({
|
return this.merge({
|
||||||
anchorKey: start.key,
|
anchorKey: start.key,
|
||||||
anchorOffset: 0,
|
anchorOffset: 0,
|
||||||
|
@@ -1,23 +0,0 @@
|
|||||||
|
|
||||||
/**
|
|
||||||
* Get leaf text for a node
|
|
||||||
*
|
|
||||||
* @param {Node} node
|
|
||||||
* @return {Text}
|
|
||||||
*/
|
|
||||||
|
|
||||||
function getLeafText(node) {
|
|
||||||
if (node.kind == 'text') {
|
|
||||||
return node
|
|
||||||
}
|
|
||||||
|
|
||||||
return node.getFirstText()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Export.
|
|
||||||
*
|
|
||||||
* @type {Function}
|
|
||||||
*/
|
|
||||||
|
|
||||||
export default getLeafText
|
|
Reference in New Issue
Block a user