mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-04-19 21:01:57 +02:00
fixes
This commit is contained in:
parent
e85ada45e9
commit
e38ddf4c30
@ -106,7 +106,7 @@ class Editor extends React.Component {
|
||||
renderNode={this.props.renderNode}
|
||||
state={this.props.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 Selection from './selection'
|
||||
import Text from './text'
|
||||
import toCamel from 'to-camel-case'
|
||||
import { OrderedMap, Record, Stack } from 'immutable'
|
||||
@ -304,13 +305,17 @@ class State extends StateRecord {
|
||||
// Determine what the selection should be after deleting.
|
||||
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 previous = state.getPreviousNode(parent).nodes.first()
|
||||
selection = selection.moveToEndOf(previous)
|
||||
}
|
||||
|
||||
else if (state.isCollapsed && !state.isAtEndOf(state)) {
|
||||
else if (!state.isAtEndOf(state)) {
|
||||
selection = selection.moveBackward(n)
|
||||
}
|
||||
|
||||
@ -364,7 +369,16 @@ class State extends StateRecord {
|
||||
|
||||
deleteForward(n = 1) {
|
||||
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.merge({ selection })
|
||||
return state
|
||||
}
|
||||
|
||||
@ -441,18 +455,23 @@ class State extends StateRecord {
|
||||
|
||||
// When the data is a string of characters...
|
||||
if (typeof data == 'string') {
|
||||
|
||||
// Insert text at the current cursor.
|
||||
const ranges = [{ text: data }]
|
||||
let { startNode, startOffset } = state
|
||||
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.
|
||||
const resumeOffset = startOffset + data.length - 1
|
||||
characters = characters.slice(0, startOffset)
|
||||
.concat(newCharacters)
|
||||
.concat(characters.slice(startOffset + size - 1, Infinity))
|
||||
.concat(characters.slice(resumeOffset, Infinity))
|
||||
|
||||
// Update the existing text node.
|
||||
startNode = startNode.merge({ characters })
|
||||
|
Loading…
x
Reference in New Issue
Block a user