feat: add extendEmptyMarkRange option to mark commands (#1859)
This commit is contained in:
@@ -9,17 +9,27 @@ declare module '@tiptap/core' {
|
||||
/**
|
||||
* Toggle a mark on and off.
|
||||
*/
|
||||
toggleMark: (typeOrName: string | MarkType, attributes?: Record<string, any>) => ReturnType,
|
||||
toggleMark: (
|
||||
typeOrName: string | MarkType,
|
||||
attributes?: Record<string, any>,
|
||||
options?: {
|
||||
/**
|
||||
* Removes the mark even across the current selection. Defaults to `false`.
|
||||
*/
|
||||
extendEmptyMarkRange?: boolean,
|
||||
},
|
||||
) => ReturnType,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const toggleMark: RawCommands['toggleMark'] = (typeOrName, attributes = {}) => ({ state, commands }) => {
|
||||
export const toggleMark: RawCommands['toggleMark'] = (typeOrName, attributes = {}, options = {}) => ({ state, commands }) => {
|
||||
const { extendEmptyMarkRange = false } = options
|
||||
const type = getMarkType(typeOrName, state.schema)
|
||||
const isActive = isMarkActive(state, type, attributes)
|
||||
|
||||
if (isActive) {
|
||||
return commands.unsetMark(type)
|
||||
return commands.unsetMark(type, { extendEmptyMarkRange })
|
||||
}
|
||||
|
||||
return commands.setMark(type, attributes)
|
||||
|
||||
Reference in New Issue
Block a user