Repository navigation
fix(gapcursor): don't offer gap cursor after comments and footnotes #9626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,8 @@ import { ListItem } from '@tiptap/extension-list' | |
| import Placeholder from '@tiptap/extension-placeholder' | ||
| import Text from '@tiptap/extension-text' | ||
| import { CharacterCount, Dropcursor, Gapcursor } from '@tiptap/extensions' | ||
| import { GapCursor } from '@tiptap/pm/gapcursor' | ||
| import { Plugin, PluginKey, Selection } from '@tiptap/pm/state' | ||
| import { common, createLowlight } from 'lowlight' | ||
| import EmojiSuggestion from '../components/Suggestion/Emoji/suggestions.js' | ||
| import MentionSuggestion from '../components/Suggestion/Mention/suggestions.js' | ||
|
|
@@ -95,6 +97,31 @@ export default Extension.create<RichTextOptions>({ | |
| // type after the first block, so without this override the gap | ||
| // cursor's textblock check rejects every position but the start. | ||
| allowGapCursor: true, | ||
|
|
||
| addProseMirrorPlugins() { | ||
| return [ | ||
| new Plugin({ | ||
| key: new PluginKey('gapCursorBeforeAnnotations'), | ||
| appendTransaction(_transactions, oldState, newState) { | ||
| const { selection, doc, schema } = newState | ||
| if (!(selection instanceof GapCursor) || selection.$head.depth > 0) { | ||
| return null | ||
| } | ||
| // A gap cursor marks where a paragraph can be inserted. With the | ||
| // override above it is also offered after `comments` and | ||
| // `footnotes`, where no paragraph is allowed. | ||
| const index = selection.$head.index() | ||
| if (doc.canReplaceWith(index, index, schema.nodes.paragraph)) { | ||
| return null | ||
| } | ||
| // Move into the neighbouring comments or footnotes, preferring | ||
| // the direction the cursor was moving in. | ||
| const dir = selection.head < oldState.selection.head ? -1 : 1 | ||
| return newState.tr.setSelection(Selection.near(selection.$head, dir)) | ||
|
Comment on lines
+119
to
+120
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With Checked in Chrome with this change on stable35 (document: one paragraph with a comment and a footnote reference, one comment, one footnote; caret at the start of the footnote):
Suggestion: never target |
||
| }, | ||
| }), | ||
| ] | ||
| }, | ||
| }), | ||
| Text, | ||
| Paragraph, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Holy moly.
Gapcursoris loaded in the line before. Does the capital c make all the difference? 😅There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hehe, yes. One is the ProseMirror plugin
GapCursor(tiptap/pmis a repackaged version of ProseMirror) and one is the Tiptap extensionGapcursorwhich builds on top of the ProseMirror plugin.