improve highlight toggling
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<div v-if="editor">
|
<div v-if="editor">
|
||||||
<button
|
<button
|
||||||
@click="editor.chain().focus().highlight().run()"
|
@click="editor.chain().focus().highlight({
|
||||||
|
color: ''
|
||||||
|
}).run()"
|
||||||
:class="{ 'is-active': editor.isActive('highlight', {
|
:class="{ 'is-active': editor.isActive('highlight', {
|
||||||
color: ''
|
color: ''
|
||||||
}) }"
|
}) }"
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { toggleMark as originalToggleMark } from 'prosemirror-commands'
|
|||||||
import { MarkType } from 'prosemirror-model'
|
import { MarkType } from 'prosemirror-model'
|
||||||
import { Command } from '../Editor'
|
import { Command } from '../Editor'
|
||||||
import getMarkType from '../utils/getMarkType'
|
import getMarkType from '../utils/getMarkType'
|
||||||
|
import markIsActive from '../utils/markIsActive'
|
||||||
|
|
||||||
type ToggleMarkCommand = (typeOrName: string | MarkType, attrs?: {}) => Command
|
type ToggleMarkCommand = (typeOrName: string | MarkType, attrs?: {}) => Command
|
||||||
|
|
||||||
@@ -11,8 +12,13 @@ declare module '../Editor' {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const toggleMark: ToggleMarkCommand = (typeOrName, attrs) => ({ state, dispatch }) => {
|
export const toggleMark: ToggleMarkCommand = (typeOrName, attrs) => ({ state, dispatch, commands }) => {
|
||||||
const type = getMarkType(typeOrName, state.schema)
|
const type = getMarkType(typeOrName, state.schema)
|
||||||
|
|
||||||
|
if (markIsActive(state, type) && !markIsActive(state, type, attrs)) {
|
||||||
|
// @ts-ignore
|
||||||
|
return commands.updateMark(type, attrs)
|
||||||
|
}
|
||||||
|
|
||||||
return originalToggleMark(type, attrs)(state, dispatch)
|
return originalToggleMark(type, attrs)(state, dispatch)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { MarkType } from 'prosemirror-model'
|
|||||||
import getMarkAttrs from './getMarkAttrs'
|
import getMarkAttrs from './getMarkAttrs'
|
||||||
|
|
||||||
export default function markHasAttributes(state: EditorState, type: MarkType, attrs?: Object) {
|
export default function markHasAttributes(state: EditorState, type: MarkType, attrs?: Object) {
|
||||||
return attrs === null || JSON.stringify(attrs) === JSON.stringify(
|
return attrs === undefined || JSON.stringify(attrs) === JSON.stringify(
|
||||||
getMarkAttrs(state, type),
|
getMarkAttrs(state, type),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user