mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-12 12:43:48 +08:00
improve commands
This commit is contained in:
parent
a97ffc41f4
commit
2bc02e50e0
@ -27,7 +27,7 @@ export type Command = (props: {
|
|||||||
chain: () => ChainedCommands,
|
chain: () => ChainedCommands,
|
||||||
state: EditorState,
|
state: EditorState,
|
||||||
view: EditorView,
|
view: EditorView,
|
||||||
dispatch: (args?: any) => any,
|
dispatch: ((args?: any) => any) | undefined,
|
||||||
}) => boolean
|
}) => boolean
|
||||||
|
|
||||||
export type CommandSpec = (...args: any[]) => Command
|
export type CommandSpec = (...args: any[]) => Command
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { wrapInList, liftListItem } from 'prosemirror-schema-list'
|
|
||||||
import { findParentNode } from 'prosemirror-utils'
|
import { findParentNode } from 'prosemirror-utils'
|
||||||
import { NodeType } from 'prosemirror-model'
|
import { NodeType } from 'prosemirror-model'
|
||||||
import { Command } from '../Editor'
|
import { Command } from '../Editor'
|
||||||
@ -28,14 +27,16 @@ export const ToggleList = createExtension({
|
|||||||
if (range.depth >= 1 && parentList && range.depth - parentList.depth <= 1) {
|
if (range.depth >= 1 && parentList && range.depth - parentList.depth <= 1) {
|
||||||
// remove list
|
// remove list
|
||||||
if (parentList.node.type === listType) {
|
if (parentList.node.type === listType) {
|
||||||
return liftListItem(itemType)(state, dispatch)
|
return commands.liftListItem(itemType)
|
||||||
}
|
}
|
||||||
|
|
||||||
// change list type
|
// change list type
|
||||||
if (isList(parentList.node.type.name, extensions) && listType.validContent(parentList.node.content)) {
|
if (isList(parentList.node.type.name, extensions) && listType.validContent(parentList.node.content)) {
|
||||||
tr.setNodeMarkup(parentList.pos, listType)
|
if (dispatch) {
|
||||||
|
tr.setNodeMarkup(parentList.pos, listType)
|
||||||
|
}
|
||||||
|
|
||||||
return false
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,13 +22,19 @@ const HardBreak = createNode({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
hardBreak: (): Command => ({
|
hardBreak: (): Command => ({ state, dispatch, view }) => {
|
||||||
tr, state, dispatch, view,
|
return chainCommands(
|
||||||
}) => {
|
exitCode,
|
||||||
return chainCommands(exitCode, () => {
|
(_, d) => {
|
||||||
dispatch(tr.replaceSelectionWith(this.type.create()).scrollIntoView())
|
if (typeof d !== 'function') {
|
||||||
return true
|
return false
|
||||||
})(state, dispatch, view)
|
}
|
||||||
|
|
||||||
|
d(state.tr.replaceSelectionWith(this.type.create()).scrollIntoView())
|
||||||
|
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
)(state, dispatch, view)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user