1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-26 08:34:28 +02:00

fix state accessors, closes #1046 (#1055)

This commit is contained in:
Ian Storm Taylor
2017-09-06 10:57:15 -07:00
committed by GitHub
parent 025a280171
commit 1075e67830

View File

@@ -101,7 +101,7 @@ class State extends new Record(DEFAULTS) {
*/ */
get hasUndos() { get hasUndos() {
return this.history.undos.length > 0 return this.history.undos.size > 0
} }
/** /**
@@ -111,7 +111,7 @@ class State extends new Record(DEFAULTS) {
*/ */
get hasRedos() { get hasRedos() {
return this.history.redos.length > 0 return this.history.redos.size > 0
} }
/** /**
@@ -261,7 +261,9 @@ class State extends new Record(DEFAULTS) {
*/ */
get startBlock() { get startBlock() {
return this.document.getClosestBlock(this.selection.startKey) return this.selection.isUnset
? null
: this.document.getClosestBlock(this.selection.startKey)
} }
/** /**
@@ -271,7 +273,9 @@ class State extends new Record(DEFAULTS) {
*/ */
get endBlock() { get endBlock() {
return this.document.getClosestBlock(this.selection.endKey) return this.selection.isUnset
? null
: this.document.getClosestBlock(this.selection.endKey)
} }
/** /**
@@ -281,7 +285,9 @@ class State extends new Record(DEFAULTS) {
*/ */
get anchorBlock() { get anchorBlock() {
return this.document.getClosestBlock(this.selection.anchorKey) return this.selection.isUnset
? null
: this.document.getClosestBlock(this.selection.anchorKey)
} }
/** /**
@@ -291,7 +297,9 @@ class State extends new Record(DEFAULTS) {
*/ */
get focusBlock() { get focusBlock() {
return this.document.getClosestBlock(this.selection.focusKey) return this.selection.isUnset
? null
: this.document.getClosestBlock(this.selection.focusKey)
} }
/** /**
@@ -301,7 +309,9 @@ class State extends new Record(DEFAULTS) {
*/ */
get startInline() { get startInline() {
return this.document.getClosestInline(this.selection.startKey) return this.selection.isUnset
? null
: this.document.getClosestInline(this.selection.startKey)
} }
/** /**
@@ -311,7 +321,9 @@ class State extends new Record(DEFAULTS) {
*/ */
get endInline() { get endInline() {
return this.document.getClosestInline(this.selection.endKey) return this.selection.isUnset
? null
: this.document.getClosestInline(this.selection.endKey)
} }
/** /**
@@ -321,7 +333,9 @@ class State extends new Record(DEFAULTS) {
*/ */
get anchorInline() { get anchorInline() {
return this.document.getClosestInline(this.selection.anchorKey) return this.selection.isUnset
? null
: this.document.getClosestInline(this.selection.anchorKey)
} }
/** /**
@@ -331,7 +345,9 @@ class State extends new Record(DEFAULTS) {
*/ */
get focusInline() { get focusInline() {
return this.document.getClosestInline(this.selection.focusKey) return this.selection.isUnset
? null
: this.document.getClosestInline(this.selection.focusKey)
} }
/** /**
@@ -341,7 +357,9 @@ class State extends new Record(DEFAULTS) {
*/ */
get startText() { get startText() {
return this.document.getDescendant(this.selection.startKey) return this.selection.isUnset
? null
: this.document.getDescendant(this.selection.startKey)
} }
/** /**
@@ -351,7 +369,9 @@ class State extends new Record(DEFAULTS) {
*/ */
get endText() { get endText() {
return this.document.getDescendant(this.selection.endKey) return this.selection.isUnset
? null
: this.document.getDescendant(this.selection.endKey)
} }
/** /**
@@ -361,7 +381,9 @@ class State extends new Record(DEFAULTS) {
*/ */
get anchorText() { get anchorText() {
return this.document.getDescendant(this.selection.anchorKey) return this.selection.isUnset
? null
: this.document.getDescendant(this.selection.anchorKey)
} }
/** /**
@@ -371,7 +393,9 @@ class State extends new Record(DEFAULTS) {
*/ */
get focusText() { get focusText() {
return this.document.getDescendant(this.selection.focusKey) return this.selection.isUnset
? null
: this.document.getDescendant(this.selection.focusKey)
} }
/** /**
@@ -381,7 +405,9 @@ class State extends new Record(DEFAULTS) {
*/ */
get characters() { get characters() {
return this.document.getCharactersAtRange(this.selection) return this.selection.isUnset
? new List()
: this.document.getCharactersAtRange(this.selection)
} }
/** /**