Skip to content

Commit

Permalink
fix: remove gap cursor (#17888)
Browse files Browse the repository at this point in the history
  • Loading branch information
daibhin committed Oct 23, 2023
1 parent dcfd9c3 commit 5100791
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions frontend/src/scenes/notebooks/Notebook/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { BacklinkCommandsExtension } from './BacklinkCommands'
import { NotebookNodeEarlyAccessFeature } from '../Nodes/NotebookNodeEarlyAccessFeature'
import { NotebookNodeSurvey } from '../Nodes/NotebookNodeSurvey'
import { InlineMenu } from './InlineMenu'
import NodeGapInsertionExtension from './Extensions/NodeGapInsertion'

const CustomDocument = ExtensionDocument.extend({
content: 'heading block*',
Expand Down Expand Up @@ -65,6 +66,7 @@ export function Editor({
CustomDocument,
StarterKit.configure({
document: false,
gapcursor: false,
}),
ExtensionPlaceholder.configure({
placeholder: placeholder,
Expand Down Expand Up @@ -98,6 +100,7 @@ export function Editor({
NotebookNodeImage,
SlashCommandsExtension,
BacklinkCommandsExtension,
NodeGapInsertionExtension,
],
content: initialContent,
editorProps: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Extension } from '@tiptap/core'
import { Plugin, PluginKey } from '@tiptap/pm/state'

const NodeGapInsertionExtension = Extension.create({
name: 'nodeGapInsertion',

addProseMirrorPlugins() {
const { editor } = this
return [
new Plugin({
key: new PluginKey('nodeGapInsertion'),
props: {
handleClick(view, pos, event) {
if (!view || !view.editable) {
return false
}
const clickPos = view.posAtCoords({ left: event.clientX, top: event.clientY })
const node = editor.state.doc.nodeAt(pos)

if (!clickPos || clickPos.inside > -1 || !node) {
return false
}

editor.commands.insertContentAt(pos, { type: 'paragraph', content: [] })
return true
},
},
}),
]
},
})

export default NodeGapInsertionExtension

0 comments on commit 5100791

Please sign in to comment.