1
0
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:
Ian Storm Taylor
2017-02-22 17:48:16 -08:00
parent 469a5fed69
commit bf4e99f200
2 changed files with 4 additions and 31 deletions

View File

@@ -1,5 +1,4 @@
import getLeafText from '../utils/get-leaf-text'
import warn from '../utils/warn'
import { Record } from 'immutable'
@@ -417,8 +416,7 @@ class Selection extends new Record(DEFAULTS) {
*/
collapseToStartOf(node) {
node = getLeafText(node)
node = node.kind == 'text' ? node : node.getFirstText()
return this.merge({
anchorKey: node.key,
anchorOffset: 0,
@@ -435,8 +433,7 @@ class Selection extends new Record(DEFAULTS) {
*/
collapseToEndOf(node) {
node = getLeafText(node)
node = node.kind == 'text' ? node : node.getLastText()
return this.merge({
anchorKey: node.key,
anchorOffset: node.length,
@@ -456,9 +453,8 @@ class Selection extends new Record(DEFAULTS) {
*/
moveToRangeOf(start, end = start) {
start = getLeafText(start)
end = getLeafText(end)
start = start.kind == 'text' ? start : start.getFirstText()
end = end.kind == 'text' ? end : end.getLastText()
return this.merge({
anchorKey: start.key,
anchorOffset: 0,

View File

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