mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-18 21:21:21 +02:00
cleanup
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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) {
|
||||
|
Reference in New Issue
Block a user