feat: setHardBreak now keeps splittable marks by default, fix #1934
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Node, mergeAttributes } from '@tiptap/core'
|
||||
|
||||
export interface HardBreakOptions {
|
||||
keepMarks: boolean,
|
||||
HTMLAttributes: Record<string, any>,
|
||||
}
|
||||
|
||||
@@ -19,6 +20,7 @@ export const HardBreak = Node.create<HardBreakOptions>({
|
||||
name: 'hardBreak',
|
||||
|
||||
defaultOptions: {
|
||||
keepMarks: true,
|
||||
HTMLAttributes: {},
|
||||
},
|
||||
|
||||
@@ -44,10 +46,34 @@ export const HardBreak = Node.create<HardBreakOptions>({
|
||||
|
||||
addCommands() {
|
||||
return {
|
||||
setHardBreak: () => ({ commands }) => {
|
||||
setHardBreak: () => ({
|
||||
commands,
|
||||
chain,
|
||||
state,
|
||||
editor,
|
||||
}) => {
|
||||
return commands.first([
|
||||
() => commands.exitCode(),
|
||||
() => commands.insertContent({ type: this.name }),
|
||||
() => commands.command(() => {
|
||||
const { keepMarks } = this.options
|
||||
const { splittableMarks } = editor.extensionManager
|
||||
const marks = state.storedMarks
|
||||
|| (state.selection.$to.parentOffset && state.selection.$from.marks())
|
||||
|
||||
return chain()
|
||||
.insertContent({ type: this.name })
|
||||
.command(({ tr, dispatch }) => {
|
||||
if (dispatch && marks && keepMarks) {
|
||||
const filteredMarks = marks
|
||||
.filter(mark => splittableMarks.includes(mark.type.name))
|
||||
|
||||
tr.ensureMarks(filteredMarks)
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
.run()
|
||||
}),
|
||||
])
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user