mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-19 13:47:51 +08:00
38 lines
879 B
TypeScript
38 lines
879 B
TypeScript
import { Command, Node } from '@tiptap/core'
|
|
import { chainCommands, exitCode } from 'prosemirror-commands'
|
|
|
|
export type HardBreakCommand = () => Command
|
|
|
|
declare module '@tiptap/core/src/Editor' {
|
|
interface Commands {
|
|
hardBreak: HardBreakCommand,
|
|
}
|
|
}
|
|
|
|
export default new Node()
|
|
.name('hardBreak')
|
|
.schema(() => ({
|
|
inline: true,
|
|
group: 'inline',
|
|
selectable: false,
|
|
parseDOM: [
|
|
{ tag: 'br' },
|
|
],
|
|
toDOM: () => ['br'],
|
|
}))
|
|
.commands(({ type }) => ({
|
|
hardBreak: () => ({
|
|
tr, state, dispatch, view,
|
|
}) => {
|
|
return chainCommands(exitCode, () => {
|
|
dispatch(tr.replaceSelectionWith(type.create()).scrollIntoView())
|
|
return true
|
|
})(state, dispatch, view)
|
|
},
|
|
}))
|
|
.keys(({ editor }) => ({
|
|
'Mod-Enter': () => editor.hardBreak(),
|
|
'Shift-Enter': () => editor.hardBreak(),
|
|
}))
|
|
.create()
|