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

refactor add/remove mark transforms

This commit is contained in:
Ian Storm Taylor
2016-11-22 14:50:17 -08:00
parent fda14bf6cd
commit d32904c7c1

View File

@@ -10,26 +10,25 @@ import Normalize from '../utils/normalize'
export function addMark(transform, mark) {
mark = Normalize.mark(mark)
const { state } = transform
const { document, selection } = state
if (selection.isExpanded) {
transform.addMarkAtRange(selection, mark)
return
}
else if (selection.marks) {
if (selection.marks) {
const marks = selection.marks.add(mark)
const sel = selection.merge({ marks })
transform.moveTo(sel)
return
}
else {
const marks = document.getMarksAtRange(selection).add(mark)
const sel = selection.merge({ marks })
transform.moveTo(sel)
}
}
/**
* Delete at the current selection.
@@ -407,20 +406,20 @@ export function removeMark(transform, mark) {
if (selection.isExpanded) {
transform.removeMarkAtRange(selection, mark)
return
}
else if (selection.marks) {
if (selection.marks) {
const marks = selection.marks.remove(mark)
const sel = selection.merge({ marks })
transform.moveTo(sel)
return
}
else {
const marks = document.getMarksAtRange(selection).remove(mark)
const sel = selection.merge({ marks })
transform.moveTo(sel)
}
}
/**
* Add or remove a `mark` from the characters in the current selection,