1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-21 14:41:23 +02:00

fix basic copy pate

This commit is contained in:
Ian Storm Taylor
2016-06-24 14:07:11 -07:00
parent cd21f2ede8
commit ce1adf1b36
2 changed files with 16 additions and 1 deletions

View File

@@ -415,7 +415,7 @@ const Node = {
const text = this.getDescendant(startKey)
const previous = this.getPreviousText(startKey)
if (!previous) return marks
const char = text.characters.get(previous.length - 1)
const char = previous.characters.get(previous.length - 1)
return char.marks
}
@@ -699,6 +699,14 @@ const Node = {
normalize() {
let node = this
const texts = node.getTextNodes()
// If there are no text nodes, add one.
if (!texts.size) {
const text = Text.create()
const nodes = node.nodes.push(text)
return node.merge({ nodes })
}
// See if there are any adjacent text nodes.
let firstAdjacent = node.findDescendant((child) => {

View File

@@ -400,9 +400,16 @@ class State extends Record(DEFAULTS) {
insertText(text) {
let state = this
let { document, selection } = state
let after = selection
// Determine what the selection should be after inserting.
if (selection.isExpanded) {
after = selection.moveToStart()
}
// Insert the text and update the selection.
document = document.insertTextAtRange(selection, text)
selection = after
selection = selection.moveForward(text.length)
state = state.merge({ document, selection })
return state