1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-18 21:21:21 +02:00
This commit is contained in:
Ian Storm Taylor
2016-06-16 12:21:39 -07:00
parent de6aeb9dfe
commit ec7da72562
3 changed files with 13 additions and 9 deletions

View File

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

View File

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

View File

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