mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-24 19:59:02 +08:00
add addMark command
This commit is contained in:
parent
127d99eb26
commit
0354f02842
15
packages/core/src/commands/addMark.ts
Normal file
15
packages/core/src/commands/addMark.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { MarkType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import getMarkType from '../utils/getMarkType'
|
||||
|
||||
export default (typeOrName: string | MarkType, attributes?: {}): Command => ({ tr, state, dispatch }) => {
|
||||
const { selection } = tr
|
||||
const type = getMarkType(typeOrName, state.schema)
|
||||
const { from, to } = selection
|
||||
|
||||
if (dispatch) {
|
||||
tr.addMark(from, to, type.create(attributes))
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
import { Extension } from '../Extension'
|
||||
import addMark from '../commands/addMark'
|
||||
import blur from '../commands/blur'
|
||||
import clearContent from '../commands/clearContent'
|
||||
import command from '../commands/command'
|
||||
@ -32,6 +33,10 @@ import wrapInList from '../commands/wrapInList'
|
||||
export const Commands = Extension.create({
|
||||
addCommands() {
|
||||
return {
|
||||
/**
|
||||
* Add a mark.
|
||||
*/
|
||||
addMark,
|
||||
/**
|
||||
* Removes focus from the editor.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user