Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/css/prosemirror.scss
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,16 @@ div.ProseMirror {
}
}

> *:first-child {
// Widgets such as the gap cursor don't take space, so make sure the top margin
// goes into the first real node.
> *:nth-child(1 of :not(:where(.ProseMirror-widget))) {
margin-top: 10px;
}

> .ProseMirror-gapcursor:first-child::after {
top: 8px;
}

> h1,
h2,
h3,
Expand Down
24 changes: 4 additions & 20 deletions src/css/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,10 @@ li.ProseMirror-selectednode {
}
}

.ProseMirror-gapcursor {
display: none;
pointer-events: none;
position: absolute;

&:after {
content: '';
display: block;
position: absolute;
top: -2px;
width: 20px;
border-top: 1px solid var(--color-main-text);
animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite;
}
}

@keyframes ProseMirror-cursor-blink {
to {
visibility: hidden;
}
// Tiptap injects its own gap cursor stylesheet (black cursor) after ours,
// so the theme colour needs a more specific selector to win.
.ProseMirror .ProseMirror-gapcursor:after {
border-top-color: var(--color-main-text);
}

.animation-rotate {
Expand Down
4 changes: 4 additions & 0 deletions src/extensions/RichText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ export default Extension.create<RichTextOptions>({
Markdown,
Document.extend({
content: 'block+ comments? footnotes?',
// The trailing `comments`/`footnotes` make `footnotes` the default
// type after the first block, so without this override the gap
// cursor's textblock check rejects every position but the start.
allowGapCursor: true,
}),
Text,
Paragraph,
Expand Down
3 changes: 3 additions & 0 deletions src/nodes/Table/TableView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ export default {
<style scoped lang="scss">
.table-wrapper {
position: relative;
// Leaves a clickable gap before the table for the gap cursor when it
// follows another table or node view. Collapses with paragraph margins.
margin-top: 1em;

&.focused,
&:hover {
Expand Down
33 changes: 33 additions & 0 deletions src/tests/extensions/Gapcursor.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { GapCursor } from '@tiptap/pm/gapcursor'
import { describe, expect } from 'vitest'
import RichText from '../../extensions/RichText.ts'
import markdownit from '../../markdownit/index.ts'
import testEditor from '../testHelpers/testEditor.ts'

// Same extension order as the real editor, so the gap cursor keymap runs
// before the table keymap.
const test = testEditor.extend({
allExtensions: [RichText.configure({ editing: true })],
})

describe('gap cursor between block nodes', () => {
test('is offered between two consecutive tables', ({ editor }) => {
editor.commands.setContent(markdownit.render('| a |\n|---|\n| 1 |\n\n| b |\n|---|\n| 2 |\n'))
const { doc } = editor.state
const between = doc.child(0).nodeSize
expect(doc.child(1).type.name).toBe('table')
// end of the text in the last cell of the first table
editor.commands.setTextSelection(between - 4)
expect(editor.state.selection.$from.parent.textContent).toBe('1')
const event = new KeyboardEvent('keydown', { key: 'ArrowRight', bubbles: true, cancelable: true })
editor.view.dom.dispatchEvent(event)
expect(event.defaultPrevented).toBe(true)
expect(editor.state.selection).toBeInstanceOf(GapCursor)
expect(editor.state.selection.from).toBe(between)
})
})
Loading