From 08b77d4c889dddb357e7caf13c92c5fe9f835b9a Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Wed, 22 Jun 2016 18:59:19 -0700 Subject: [PATCH] more cleanup --- lib/models/node.js | 14 ++++----- lib/models/selection.js | 23 +++----------- lib/models/state.js | 68 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 75 insertions(+), 30 deletions(-) diff --git a/lib/models/node.js b/lib/models/node.js index 6e394fb65..18c228df4 100644 --- a/lib/models/node.js +++ b/lib/models/node.js @@ -236,7 +236,7 @@ const Node = { getBlocksAtRange(range) { range = range.normalize(this) - const texts = this.getTextNodesAtRange(range) + const texts = this.getTextsAtRange(range) const blocks = texts.map((text) => { return this.getClosest(text, p => p.kind == 'block') }) @@ -253,7 +253,7 @@ const Node = { getCharactersAtRange(range) { range = range.normalize(this) - const texts = this.getTextNodesAtRange(range) + const texts = this.getTextsAtRange(range) let list = new List() texts.forEach((text) => { @@ -339,7 +339,7 @@ const Node = { getInlinesAtRange(range) { range = range.normalize(this) const node = this - const texts = node.getTextNodesAtRange(range) + const texts = node.getTextsAtRange(range) const inlines = texts .map(text => node.getClosest(text, p => p.kind == 'inline')) .filter(inline => inline) @@ -567,7 +567,7 @@ const Node = { * @return {OrderedMap} nodes */ - getTextNodesAtRange(range) { + getTextsAtRange(range) { range = range.normalize(this) const { startKey, endKey } = range @@ -672,7 +672,7 @@ const Node = { // Otherwise, find each of the text nodes within the range. const { startKey, startOffset, endKey, endOffset } = range - let texts = node.getTextNodesAtRange(range) + let texts = node.getTextsAtRange(range) // Apply the mark to each of the text nodes's matching characters. texts = texts.map((text) => { @@ -921,7 +921,7 @@ const Node = { if (range.isCollapsed) return node // Otherwise, find each of the text nodes within the range. - let texts = node.getTextNodesAtRange(range) + let texts = node.getTextsAtRange(range) // Apply the mark to each of the text nodes's matching characters. texts = texts.map((text) => { @@ -1228,7 +1228,7 @@ const Node = { }) // Get the furthest inline nodes in the range. - const texts = node.getTextNodesAtRange(range) + const texts = node.getTextsAtRange(range) const children = texts.map(text => node.getFurthestInline(text) || text) // Iterate each of the child nodes, wrapping them. diff --git a/lib/models/selection.js b/lib/models/selection.js index 32fa28e70..1427c44cb 100644 --- a/lib/models/selection.js +++ b/lib/models/selection.js @@ -47,8 +47,6 @@ class Selection extends SelectionRecord { /** * Get whether the selection is expanded. * - * Aliased as `isExtended` since browser implementations refer to it as both. - * * @return {Boolean} isExpanded */ @@ -56,10 +54,6 @@ class Selection extends SelectionRecord { return ! this.isCollapsed } - get isExtended() { - return this.isExpanded - } - /** * Get whether the range's anchor of focus keys are not set yet. * @@ -184,17 +178,6 @@ class Selection extends SelectionRecord { }) } - /** - * Move the selection to a set of `properties`. - * - * @param {Object} properties - * @return {State} state - */ - - moveTo(properties) { - return this.merge(properties) - } - /** * Move the focus point to the anchor point. * @@ -204,7 +187,8 @@ class Selection extends SelectionRecord { moveToAnchor() { return this.merge({ focusKey: this.anchorKey, - focusOffset: this.anchorOffset + focusOffset: this.anchorOffset, + isBackward: false }) } @@ -217,7 +201,8 @@ class Selection extends SelectionRecord { moveToFocus() { return this.merge({ anchorKey: this.focusKey, - anchorOffset: this.focusOffset + anchorOffset: this.focusOffset, + isBackward: false }) } diff --git a/lib/models/state.js b/lib/models/state.js index ec377343c..672f20be6 100644 --- a/lib/models/state.js +++ b/lib/models/state.js @@ -81,6 +81,26 @@ class State extends Record(DEFAULTS) { return this.selection.isExpanded } + /** + * Is the current selection backward? + * + * @return {Boolean} isBackward + */ + + get isCurrentlyBackward() { + return this.selection.isBackward + } + + /** + * Is the current selection forward? + * + * @return {Boolean} isForward + */ + + get isCurrentlyForward() { + return this.selection.isForward + } + /** * Get the current start key. * @@ -121,6 +141,46 @@ class State extends Record(DEFAULTS) { return this.selection.endOffset } + /** + * Get the current anchor key. + * + * @return {String} anchorKey + */ + + get currentAnchorKey() { + return this.selection.anchorKey + } + + /** + * Get the current focus key. + * + * @return {String} focusKey + */ + + get currentFocusKey() { + return this.selection.focusKey + } + + /** + * Get the current anchor offset. + * + * @return {String} anchorOffset + */ + + get currentAnchorOffset() { + return this.selection.anchorOffset + } + + /** + * Get the current focus offset. + * + * @return {String} focusOffset + */ + + get currentFocusOffset() { + return this.selection.focusOffset + } + /** * Get the characters in the current selection. * @@ -147,7 +207,7 @@ class State extends Record(DEFAULTS) { * @return {OrderedMap} nodes */ - get currentBlockNodes() { + get currentBlocks() { return this.document.getBlocksAtRange(this.selection) } @@ -157,7 +217,7 @@ class State extends Record(DEFAULTS) { * @return {OrderedMap} nodes */ - get currentInlineNodes() { + get currentInlines() { return this.document.getInlinesAtRange(this.selection) } @@ -167,8 +227,8 @@ class State extends Record(DEFAULTS) { * @return {OrderedMap} nodes */ - get currentTextNodes() { - return this.document.getTextNodesAtRange(this.selection) + get currentTexts() { + return this.document.getTextsAtRange(this.selection) } /**