1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-30 18:39:51 +02:00

more cleanup

This commit is contained in:
Ian Storm Taylor
2016-06-22 18:59:19 -07:00
parent d6a225df8f
commit 08b77d4c88
3 changed files with 75 additions and 30 deletions

View File

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

View File

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

View File

@@ -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)
}
/**