mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-09-02 19:52:32 +02:00
refactor add/remove mark transforms
This commit is contained in:
@@ -10,26 +10,25 @@ import Normalize from '../utils/normalize'
|
|||||||
|
|
||||||
export function addMark(transform, mark) {
|
export function addMark(transform, mark) {
|
||||||
mark = Normalize.mark(mark)
|
mark = Normalize.mark(mark)
|
||||||
|
|
||||||
const { state } = transform
|
const { state } = transform
|
||||||
const { document, selection } = state
|
const { document, selection } = state
|
||||||
|
|
||||||
if (selection.isExpanded) {
|
if (selection.isExpanded) {
|
||||||
transform.addMarkAtRange(selection, mark)
|
transform.addMarkAtRange(selection, mark)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (selection.marks) {
|
if (selection.marks) {
|
||||||
const marks = selection.marks.add(mark)
|
const marks = selection.marks.add(mark)
|
||||||
const sel = selection.merge({ marks })
|
const sel = selection.merge({ marks })
|
||||||
transform.moveTo(sel)
|
transform.moveTo(sel)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
|
||||||
const marks = document.getMarksAtRange(selection).add(mark)
|
const marks = document.getMarksAtRange(selection).add(mark)
|
||||||
const sel = selection.merge({ marks })
|
const sel = selection.merge({ marks })
|
||||||
transform.moveTo(sel)
|
transform.moveTo(sel)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete at the current selection.
|
* Delete at the current selection.
|
||||||
@@ -407,20 +406,20 @@ export function removeMark(transform, mark) {
|
|||||||
|
|
||||||
if (selection.isExpanded) {
|
if (selection.isExpanded) {
|
||||||
transform.removeMarkAtRange(selection, mark)
|
transform.removeMarkAtRange(selection, mark)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (selection.marks) {
|
if (selection.marks) {
|
||||||
const marks = selection.marks.remove(mark)
|
const marks = selection.marks.remove(mark)
|
||||||
const sel = selection.merge({ marks })
|
const sel = selection.merge({ marks })
|
||||||
transform.moveTo(sel)
|
transform.moveTo(sel)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
|
||||||
const marks = document.getMarksAtRange(selection).remove(mark)
|
const marks = document.getMarksAtRange(selection).remove(mark)
|
||||||
const sel = selection.merge({ marks })
|
const sel = selection.merge({ marks })
|
||||||
transform.moveTo(sel)
|
transform.moveTo(sel)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add or remove a `mark` from the characters in the current selection,
|
* Add or remove a `mark` from the characters in the current selection,
|
||||||
|
Reference in New Issue
Block a user