diff --git a/lib/components/editor.js b/lib/components/editor.js index 2b3bb0779..16897513f 100644 --- a/lib/components/editor.js +++ b/lib/components/editor.js @@ -65,7 +65,7 @@ class Editor extends React.Component { onKeyDown(e) { for (const plugin of this.state.plugins) { if (plugin.onKeyDown) { - const newState = plugin.onKeyDown(e, this) + const newState = plugin.onKeyDown(e, this.props.state, this) if (newState == null) continue this.props.onChange(newState) break diff --git a/lib/models/state.js b/lib/models/state.js index 73089f7c1..46b1e398b 100644 --- a/lib/models/state.js +++ b/lib/models/state.js @@ -53,7 +53,7 @@ class State extends StateRecord { setNode(key, node) { if (this.nodes.get(key)) { const nodes = this.nodes.set(key, node) - return this.set('nodes', nodes) + return this.merge({ nodes }) } const nodes = this.nodes.map((child) => { @@ -62,7 +62,7 @@ class State extends StateRecord { : child }) - return this.set('nodes', nodes) + return this.merge({ nodes }) } /** @@ -152,11 +152,13 @@ class State extends StateRecord { collapseBackward() { let { selection } = this let { anchorKey, anchorOffset } = selection + selection = selection.merge({ focusKey: anchorKey, focusOffset: anchorOffset }) - let state = this.set('selection', selection) + + let state = this.merge({ selection }) return state } @@ -169,11 +171,13 @@ class State extends StateRecord { collapseForward() { let { selection } = this let { focusKey, focusOffset } = selection + selection = selection.merge({ anchorKey: focusKey, anchorOffset: focusOffset }) - let state = this.set('selection', selection) + + let state = this.merge({ selection }) return state } @@ -246,7 +250,7 @@ class State extends StateRecord { .take(Infinity) // ...and remove the text from the first and last nodes - let state = this.set('nodes', nodes) + let state = this.merge({ nodes }) state = state.removeText(startNode, startOffset, startNode.text.length) state = state.removeText(endNode, 0, endOffset) return state @@ -269,7 +273,7 @@ class State extends StateRecord { return startOffset <= i && i < endOffset }) - node = node.set('characters', characters) + node = node.merge({ characters }) let state = this.setNode(node.key, node) return state } diff --git a/lib/plugins/core.js b/lib/plugins/core.js index 454081b19..c76e0263a 100644 --- a/lib/plugins/core.js +++ b/lib/plugins/core.js @@ -12,12 +12,12 @@ const CORE_PLUGIN = { * The core `onKeyDown` handler. * * @param {Event} e + * @param {State} state * @param {Editor} editor * @return {State or Null} newState */ - onKeyDown(e, editor) { - const state = editor.getState() + onKeyDown(e, state, editor) { const key = keycode(e.which) switch (key) {