diff --git a/frontend/src/scenes/notebooks/Notebook/Editor.tsx b/frontend/src/scenes/notebooks/Notebook/Editor.tsx index 7866a61617f87..c9067210fa415 100644 --- a/frontend/src/scenes/notebooks/Notebook/Editor.tsx +++ b/frontend/src/scenes/notebooks/Notebook/Editor.tsx @@ -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*', @@ -65,6 +66,7 @@ export function Editor({ CustomDocument, StarterKit.configure({ document: false, + gapcursor: false, }), ExtensionPlaceholder.configure({ placeholder: placeholder, @@ -98,6 +100,7 @@ export function Editor({ NotebookNodeImage, SlashCommandsExtension, BacklinkCommandsExtension, + NodeGapInsertionExtension, ], content: initialContent, editorProps: { diff --git a/frontend/src/scenes/notebooks/Notebook/Extensions/NodeGapInsertion.ts b/frontend/src/scenes/notebooks/Notebook/Extensions/NodeGapInsertion.ts new file mode 100644 index 0000000000000..4fad7ba098a1a --- /dev/null +++ b/frontend/src/scenes/notebooks/Notebook/Extensions/NodeGapInsertion.ts @@ -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