refac: inline codespan rich text input
Co-Authored-By: Abdul Moiz <86627657+abdulmoizjawed@users.noreply.github.com>
This commit is contained in:
co-authored by
Abdul Moiz
parent
bc5d519c4f
commit
e303c3da3b
@@ -114,7 +114,7 @@
|
||||
import { Fragment, DOMParser } from 'prosemirror-model';
|
||||
import { EditorState, Plugin, PluginKey, TextSelection, Selection } from 'prosemirror-state';
|
||||
import { Decoration, DecorationSet } from 'prosemirror-view';
|
||||
import { Editor, Extension, mergeAttributes } from '@tiptap/core';
|
||||
import { Editor, Extension, markInputRule, mergeAttributes } from '@tiptap/core';
|
||||
|
||||
import { AIAutocompletion } from './RichTextInput/AutoCompletion.js';
|
||||
|
||||
@@ -135,8 +135,26 @@
|
||||
import FileHandler from '@tiptap/extension-file-handler';
|
||||
import Typography from '@tiptap/extension-typography';
|
||||
import Highlight from '@tiptap/extension-highlight';
|
||||
import Code from '@tiptap/extension-code';
|
||||
import CodeBlockLowlight from '@tiptap/extension-code-block-lowlight';
|
||||
|
||||
// WORKAROUND: TipTap's default Code mark input rule regex captures the
|
||||
// character before the opening backtick, causing it to be deleted.
|
||||
// This uses a lookbehind assertion instead so the preceding character is
|
||||
// matched for position but not captured/deleted.
|
||||
// Upstream fix: https://github.com/ueberdosis/tiptap/pull/7124
|
||||
const backtickInputRegex = /(?<=\s|^)`([^`]+)`(?!`)$/;
|
||||
const FixedCode = Code.extend({
|
||||
addInputRules() {
|
||||
return [
|
||||
markInputRule({
|
||||
find: backtickInputRegex,
|
||||
type: this.type
|
||||
})
|
||||
];
|
||||
}
|
||||
});
|
||||
|
||||
import Mention from '@tiptap/extension-mention';
|
||||
import FormattingButtons from './RichTextInput/FormattingButtons.svelte';
|
||||
|
||||
@@ -692,12 +710,14 @@
|
||||
extensions: [
|
||||
StarterKit.configure({
|
||||
link: link,
|
||||
code: false, // Disabled in favor of FixedCode (see workaround above)
|
||||
// When rich text is off, disable Strike from StarterKit so we can
|
||||
// re-add it below without its Mod-Shift-s shortcut (which conflicts
|
||||
// with the Toggle Sidebar shortcut). When rich text is on, the user
|
||||
// can undo strikethrough via the toolbar, so the shortcut is fine.
|
||||
...(richText ? {} : { strike: false })
|
||||
}),
|
||||
FixedCode,
|
||||
...(dragHandle ? [ListItemDragHandle] : []),
|
||||
Placeholder.configure({ placeholder: () => _placeholder, showOnlyWhenEditable: false }),
|
||||
SelectionDecoration,
|
||||
|
||||
Reference in New Issue
Block a user