From bf4e99f20021512e95278bcaa969c9e856cc14e3 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Wed, 22 Feb 2017 17:48:16 -0800 Subject: [PATCH] fix moveToRangeOf, collapseToStart/EndOf --- src/models/selection.js | 12 ++++-------- src/utils/get-leaf-text.js | 23 ----------------------- 2 files changed, 4 insertions(+), 31 deletions(-) delete mode 100644 src/utils/get-leaf-text.js diff --git a/src/models/selection.js b/src/models/selection.js index 47f951e63..9a00cd5ff 100644 --- a/src/models/selection.js +++ b/src/models/selection.js @@ -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, diff --git a/src/utils/get-leaf-text.js b/src/utils/get-leaf-text.js deleted file mode 100644 index 83fd761f9..000000000 --- a/src/utils/get-leaf-text.js +++ /dev/null @@ -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