mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-07 09:25:29 +08:00
feat: escape code blocks on triple enter, fix #2195
This commit is contained in:
parent
8347f58167
commit
d48fb24ee2
@ -118,6 +118,34 @@ export const CodeBlock = Node.create<CodeBlockOptions>({
|
||||
|
||||
return false
|
||||
},
|
||||
|
||||
// escape node on triple enter
|
||||
Enter: ({ editor }) => {
|
||||
const { state } = editor
|
||||
const { selection } = state
|
||||
const { $from, empty } = selection
|
||||
|
||||
if (!empty || $from.parent.type !== this.type) {
|
||||
return false
|
||||
}
|
||||
|
||||
const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2
|
||||
const endsWithDoubleNewline = $from.parent.textContent.endsWith('\n\n')
|
||||
|
||||
if (!isAtEnd || !endsWithDoubleNewline) {
|
||||
return false
|
||||
}
|
||||
|
||||
return editor
|
||||
.chain()
|
||||
.command(({ tr }) => {
|
||||
tr.delete($from.pos - 2, $from.pos)
|
||||
|
||||
return true
|
||||
})
|
||||
.exitCode()
|
||||
.run()
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user