mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-12 18:24:03 +02:00
fixes
This commit is contained in:
@@ -106,7 +106,7 @@ class Editor extends React.Component {
|
|||||||
renderNode={this.props.renderNode}
|
renderNode={this.props.renderNode}
|
||||||
state={this.props.state}
|
state={this.props.state}
|
||||||
onChange={state => this.onChange(state)}
|
onChange={state => this.onChange(state)}
|
||||||
onKeyDown={e => this.onEvent('keyDown', e)}
|
onKeyDown={e => this.onEvent('onKeyDown', e)}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
import Selection from './selection'
|
import Character from './character'
|
||||||
import Node from './node'
|
import Node from './node'
|
||||||
|
import Selection from './selection'
|
||||||
import Text from './text'
|
import Text from './text'
|
||||||
import toCamel from 'to-camel-case'
|
import toCamel from 'to-camel-case'
|
||||||
import { OrderedMap, Record, Stack } from 'immutable'
|
import { OrderedMap, Record, Stack } from 'immutable'
|
||||||
@@ -304,13 +305,17 @@ class State extends StateRecord {
|
|||||||
// Determine what the selection should be after deleting.
|
// Determine what the selection should be after deleting.
|
||||||
const startNode = state.startNode
|
const startNode = state.startNode
|
||||||
|
|
||||||
if (state.isCollapsed && state.isAtStartOf(startNode)) {
|
if (state.isExpanded) {
|
||||||
|
selection = selection.moveToStart()
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (state.isAtStartOf(startNode)) {
|
||||||
const parent = state.getParentNode(startNode)
|
const parent = state.getParentNode(startNode)
|
||||||
const previous = state.getPreviousNode(parent).nodes.first()
|
const previous = state.getPreviousNode(parent).nodes.first()
|
||||||
selection = selection.moveToEndOf(previous)
|
selection = selection.moveToEndOf(previous)
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (state.isCollapsed && !state.isAtEndOf(state)) {
|
else if (!state.isAtEndOf(state)) {
|
||||||
selection = selection.moveBackward(n)
|
selection = selection.moveBackward(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,7 +369,16 @@ class State extends StateRecord {
|
|||||||
|
|
||||||
deleteForward(n = 1) {
|
deleteForward(n = 1) {
|
||||||
let state = this
|
let state = this
|
||||||
|
let selection = state.selection
|
||||||
|
|
||||||
|
// Determine what the selection should be after deleting.
|
||||||
|
if (state.isExpanded) {
|
||||||
|
selection = selection.moveToStart()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete forward and then update the selection.
|
||||||
state = state.deleteForwardAtRange(state.selection)
|
state = state.deleteForwardAtRange(state.selection)
|
||||||
|
state = state.merge({ selection })
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -441,18 +455,23 @@ class State extends StateRecord {
|
|||||||
|
|
||||||
// When the data is a string of characters...
|
// When the data is a string of characters...
|
||||||
if (typeof data == 'string') {
|
if (typeof data == 'string') {
|
||||||
|
|
||||||
// Insert text at the current cursor.
|
|
||||||
const ranges = [{ text: data }]
|
|
||||||
let { startNode, startOffset } = state
|
let { startNode, startOffset } = state
|
||||||
let { characters } = startNode
|
let { characters } = startNode
|
||||||
let newCharacters = convertRangesToCharacters(ranges)
|
|
||||||
const { size } = newCharacters
|
// Create a list of the new characters, with the right marks.
|
||||||
|
const { marks } = characters.get(startOffset)
|
||||||
|
const newCharacters = data.split('').reduce((list, char) => {
|
||||||
|
return list.push(Character.create({
|
||||||
|
text: char,
|
||||||
|
marks
|
||||||
|
}))
|
||||||
|
}, Character.createList())
|
||||||
|
|
||||||
// Splice in the new characters.
|
// Splice in the new characters.
|
||||||
|
const resumeOffset = startOffset + data.length - 1
|
||||||
characters = characters.slice(0, startOffset)
|
characters = characters.slice(0, startOffset)
|
||||||
.concat(newCharacters)
|
.concat(newCharacters)
|
||||||
.concat(characters.slice(startOffset + size - 1, Infinity))
|
.concat(characters.slice(resumeOffset, Infinity))
|
||||||
|
|
||||||
// Update the existing text node.
|
// Update the existing text node.
|
||||||
startNode = startNode.merge({ characters })
|
startNode = startNode.merge({ characters })
|
||||||
|
Reference in New Issue
Block a user