From b7eb15dfad585aba78ba97dbfe9bf44f357ce231 Mon Sep 17 00:00:00 2001 From: LiJung Chi Date: Wed, 12 Oct 2016 00:41:42 +0800 Subject: [PATCH] fix #342, Uncaught Error: Invalid `key` argument when `removeNodeByKey` (#365) * fix #342, Uncaught Error: Invalid `key` argument when `removeNodeByKey` * return List() and use selection.isUnset instead * fix default value when this.selection.isUnset --- src/models/state.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/models/state.js b/src/models/state.js index 989bed905..56ead2f7e 100644 --- a/src/models/state.js +++ b/src/models/state.js @@ -5,7 +5,7 @@ import Mark from './mark' import Selection from './selection' import Transform from './transform' import uid from '../utils/uid' -import { Record, Set, Stack } from 'immutable' +import { Record, Set, Stack, List } from 'immutable' /** * History. @@ -361,7 +361,9 @@ class State extends new Record(DEFAULTS) { */ get marks() { - return this.selection.marks || this.document.getMarksAtRange(this.selection) + return this.selection.isUnset + ? new Set() + : this.selection.marks || this.document.getMarksAtRange(this.selection) } /** @@ -371,7 +373,9 @@ class State extends new Record(DEFAULTS) { */ get blocks() { - return this.document.getBlocksAtRange(this.selection) + return this.selection.isUnset + ? new List() + : this.document.getBlocksAtRange(this.selection) } /** @@ -381,7 +385,9 @@ class State extends new Record(DEFAULTS) { */ get fragment() { - return this.document.getFragmentAtRange(this.selection) + return this.selection.isUnset + ? Document.create() + : this.document.getFragmentAtRange(this.selection) } /** @@ -391,7 +397,9 @@ class State extends new Record(DEFAULTS) { */ get inlines() { - return this.document.getInlinesAtRange(this.selection) + return this.selection.isUnset + ? new List() + : this.document.getInlinesAtRange(this.selection) } /** @@ -401,7 +409,9 @@ class State extends new Record(DEFAULTS) { */ get texts() { - return this.document.getTextsAtRange(this.selection) + return this.selection.isUnset + ? new List() + : this.document.getTextsAtRange(this.selection) } /**