1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-09-01 03:11:44 +02:00

refactor insert text and selection mark updating

This commit is contained in:
Ian Storm Taylor
2016-11-22 15:23:24 -08:00
parent f393973cfa
commit da4c1ffcaf
3 changed files with 15 additions and 22 deletions

View File

@@ -221,29 +221,10 @@ export function insertInline(transform, inline) {
export function insertText(transform, text, marks) {
const { state } = transform
const { document, selection } = state
const { startKey } = selection
const isVoid = document.hasVoidParent(startKey)
let after
if (isVoid) {
after = selection
}
else if (selection.isExpanded) {
after = selection.collapseToStart().moveForward(text.length)
}
else {
after = selection.moveForward(text.length)
}
const { selection } = state
marks = marks || selection.marks
transform
.unsetSelection()
.insertTextAtRange(selection, text, marks)
.moveTo(after)
transform.insertTextAtRange(selection, text, marks)
transform.unsetMarks()
}
/**

View File

@@ -129,6 +129,7 @@ import {
moveTo,
moveToOffsets,
moveToRangeOf,
unsetMarks,
unsetSelection,
} from './on-selection'
@@ -281,6 +282,7 @@ export default {
moveTo,
moveToOffsets,
moveToRangeOf,
unsetMarks,
unsetSelection,
/**

View File

@@ -374,6 +374,16 @@ export function moveToRangeOf(transform, start, end) {
transform.setSelectionOperation(sel)
}
/**
* Unset the selection's marks.
*
* @param {Transform} transform
*/
export function unsetMarks(transform) {
transform.setSelectionOperation({ marks: null })
}
/**
* Unset the selection, removing an association to a node.
*