mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-20 22:21:20 +02:00
Fix undoing setMark
This commit is contained in:
@@ -311,19 +311,18 @@ class Text extends new Record(DEFAULTS) {
|
||||
* @param {Number} index
|
||||
* @param {Number} length
|
||||
* @param {Mark} mark
|
||||
* @param {Object} properties
|
||||
* @param {Mark} newMark
|
||||
* @return {Text}
|
||||
*/
|
||||
|
||||
updateMark(index, length, mark, properties) {
|
||||
const m = mark.merge(properties)
|
||||
updateMark(index, length, mark, newMark) {
|
||||
const characters = this.characters.map((char, i) => {
|
||||
if (i < index) return char
|
||||
if (i >= index + length) return char
|
||||
let { marks } = char
|
||||
if (!marks.has(mark)) return char
|
||||
marks = marks.remove(mark)
|
||||
marks = marks.add(m)
|
||||
marks = marks.add(newMark)
|
||||
char = char.merge({ marks })
|
||||
return char
|
||||
})
|
||||
|
@@ -326,10 +326,10 @@ function removeText(state, operation) {
|
||||
*/
|
||||
|
||||
function setMark(state, operation) {
|
||||
const { path, offset, length, mark, properties } = operation
|
||||
const { path, offset, length, mark, newMark } = operation
|
||||
let { document } = state
|
||||
let node = document.assertPath(path)
|
||||
node = node.updateMark(offset, length, mark, properties)
|
||||
node = node.updateMark(offset, length, mark, newMark)
|
||||
document = document.updateDescendant(node)
|
||||
state = state.merge({ document })
|
||||
return state
|
||||
|
@@ -248,11 +248,12 @@ export function setMarkByKey(transform, key, offset, length, mark, properties, o
|
||||
const { normalize = true } = options
|
||||
mark = Normalize.mark(mark)
|
||||
properties = Normalize.markProperties(properties)
|
||||
const newMark = mark.merge(properties)
|
||||
const { state } = transform
|
||||
const { document } = state
|
||||
const path = document.getPath(key)
|
||||
|
||||
transform = transform.setMarkOperation(path, offset, length, mark, properties)
|
||||
transform = transform.setMarkOperation(path, offset, length, mark, newMark)
|
||||
if (normalize) {
|
||||
const parent = document.getParent(key)
|
||||
transform = transform.normalizeNodeByKey(parent.key)
|
||||
|
@@ -290,23 +290,18 @@ export function removeTextOperation(transform, path, offset, length) {
|
||||
* @param {Number} offset
|
||||
* @param {Number} length
|
||||
* @param {Mark} mark
|
||||
* @param {Mark} newMark
|
||||
* @return {Transform}
|
||||
*/
|
||||
|
||||
export function setMarkOperation(transform, path, offset, length, mark, properties) {
|
||||
const inverseProps = {}
|
||||
|
||||
for (const k in properties) {
|
||||
inverseProps[k] = mark[k]
|
||||
}
|
||||
|
||||
export function setMarkOperation(transform, path, offset, length, mark, newMark) {
|
||||
const inverse = [{
|
||||
type: 'set_mark',
|
||||
path,
|
||||
offset,
|
||||
length,
|
||||
mark,
|
||||
properties: inverseProps,
|
||||
mark: newMark,
|
||||
newMark: mark
|
||||
}]
|
||||
|
||||
const operation = {
|
||||
@@ -315,7 +310,7 @@ export function setMarkOperation(transform, path, offset, length, mark, properti
|
||||
offset,
|
||||
length,
|
||||
mark,
|
||||
properties,
|
||||
newMark,
|
||||
inverse,
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user