2020-09-10 17:42:55 +08:00
|
|
|
import { Node } from '@tiptap/core'
|
|
|
|
import { chainCommands, exitCode } from 'prosemirror-commands'
|
|
|
|
|
|
|
|
declare module '@tiptap/core/src/Editor' {
|
|
|
|
interface Editor {
|
2020-09-10 17:50:34 +08:00
|
|
|
hardBreak(): Editor,
|
2020-09-10 17:42:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default new Node()
|
2020-09-10 17:50:34 +08:00
|
|
|
.name('hardBreak')
|
2020-09-10 17:42:55 +08:00
|
|
|
.schema(() => ({
|
|
|
|
inline: true,
|
|
|
|
group: 'inline',
|
|
|
|
selectable: false,
|
|
|
|
parseDOM: [
|
|
|
|
{ tag: 'br' },
|
|
|
|
],
|
|
|
|
toDOM: () => ['br'],
|
|
|
|
}))
|
2020-09-22 05:17:30 +08:00
|
|
|
// .commands(({ editor, type }) => ({
|
|
|
|
// hardBreak: next => () => {
|
|
|
|
// const { state, view } = editor
|
|
|
|
// const { dispatch } = view
|
2020-09-10 17:42:55 +08:00
|
|
|
|
2020-09-22 05:17:30 +08:00
|
|
|
// chainCommands(exitCode, () => {
|
|
|
|
// dispatch(state.tr.replaceSelectionWith(type.create()).scrollIntoView())
|
|
|
|
// return true
|
|
|
|
// })(state, dispatch, view)
|
2020-09-10 17:42:55 +08:00
|
|
|
|
2020-09-22 05:17:30 +08:00
|
|
|
// next()
|
|
|
|
// },
|
|
|
|
// }))
|
2020-09-10 17:42:55 +08:00
|
|
|
.keys(({ editor }) => ({
|
2020-09-10 17:50:34 +08:00
|
|
|
'Mod-Enter': () => editor.hardBreak(),
|
|
|
|
'Shift-Enter': () => editor.hardBreak(),
|
2020-09-10 17:42:55 +08:00
|
|
|
}))
|
|
|
|
.create()
|