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