|
114 | 114 | import { Fragment, DOMParser } from 'prosemirror-model'; |
115 | 115 | import { EditorState, Plugin, PluginKey, TextSelection, Selection } from 'prosemirror-state'; |
116 | 116 | import { Decoration, DecorationSet } from 'prosemirror-view'; |
117 | | - import { Editor, Extension, mergeAttributes } from '@tiptap/core'; |
| 117 | + import { Editor, Extension, markInputRule, mergeAttributes } from '@tiptap/core'; |
118 | 118 |
|
119 | 119 | import { AIAutocompletion } from './RichTextInput/AutoCompletion.js'; |
120 | 120 |
|
|
135 | 135 | import FileHandler from '@tiptap/extension-file-handler'; |
136 | 136 | import Typography from '@tiptap/extension-typography'; |
137 | 137 | import Highlight from '@tiptap/extension-highlight'; |
| 138 | + import Code from '@tiptap/extension-code'; |
138 | 139 | import CodeBlockLowlight from '@tiptap/extension-code-block-lowlight'; |
139 | 140 |
|
| 141 | + // WORKAROUND: TipTap's default Code mark input rule regex captures the |
| 142 | + // character before the opening backtick, causing it to be deleted. |
| 143 | + // This uses a lookbehind assertion instead so the preceding character is |
| 144 | + // matched for position but not captured/deleted. |
| 145 | + // Upstream fix: https://github.com/ueberdosis/tiptap/pull/7124 |
| 146 | + const backtickInputRegex = /(?<=\s|^)`([^`]+)`(?!`)$/; |
| 147 | + const FixedCode = Code.extend({ |
| 148 | + addInputRules() { |
| 149 | + return [ |
| 150 | + markInputRule({ |
| 151 | + find: backtickInputRegex, |
| 152 | + type: this.type |
| 153 | + }) |
| 154 | + ]; |
| 155 | + } |
| 156 | + }); |
| 157 | +
|
140 | 158 | import Mention from '@tiptap/extension-mention'; |
141 | 159 | import FormattingButtons from './RichTextInput/FormattingButtons.svelte'; |
142 | 160 |
|
|
692 | 710 | extensions: [ |
693 | 711 | StarterKit.configure({ |
694 | 712 | link: link, |
| 713 | + code: false, // Disabled in favor of FixedCode (see workaround above) |
695 | 714 | // When rich text is off, disable Strike from StarterKit so we can |
696 | 715 | // re-add it below without its Mod-Shift-s shortcut (which conflicts |
697 | 716 | // with the Toggle Sidebar shortcut). When rich text is on, the user |
698 | 717 | // can undo strikethrough via the toolbar, so the shortcut is fine. |
699 | 718 | ...(richText ? {} : { strike: false }) |
700 | 719 | }), |
| 720 | + FixedCode, |
701 | 721 | ...(dragHandle ? [ListItemDragHandle] : []), |
702 | 722 | Placeholder.configure({ placeholder: () => _placeholder, showOnlyWhenEditable: false }), |
703 | 723 | SelectionDecoration, |
|
0 commit comments