Skip to content

Commit de5fcf5

Browse files
feat(web): add textShortcuts support
1 parent 4eed699 commit de5fcf5

4 files changed

Lines changed: 339 additions & 24 deletions

File tree

src/web/EnrichedTextInput.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import {
7474
} from './pmPlugins/MentionPlugin';
7575
import { StripMarksOnImagePlugin } from './pmPlugins/StripMarksOnImagePlugin';
7676
import { ShortcutPlugin } from './pmPlugins/ShortcutPlugin';
77+
import { TextShortcutsPlugin } from './pmPlugins/TextShortcutsPlugin';
7778
import { returnKeyTypeToEnterKeyHint } from './returnKeyTypeToEnterKeyHint';
7879
import { AutolinkPlugin } from './pmPlugins/AutolinkPlugin';
7980

@@ -116,6 +117,7 @@ export const EnrichedTextInput = ({
116117
linkRegex,
117118
htmlStyle,
118119
useHtmlNormalizer,
120+
textShortcuts = ENRICHED_TEXT_INPUT_DEFAULT_PROPS.textShortcuts,
119121
}: EnrichedTextInputProps) => {
120122
const tiptapContent =
121123
defaultValue != null
@@ -142,6 +144,11 @@ export const EnrichedTextInput = ({
142144
mentionIndicatorsRef.current = mentionIndicators;
143145
}, [mentionIndicators]);
144146

147+
const textShortcutsRef = useRef(textShortcuts);
148+
useEffect(() => {
149+
textShortcutsRef.current = textShortcuts;
150+
}, [textShortcuts]);
151+
145152
const mentionCallbacksRef = useRef({
146153
onStartMention,
147154
onChangeMention,
@@ -244,6 +251,10 @@ export const EnrichedTextInput = ({
244251
ShortcutPlugin.configure({
245252
getHtmlStyle: () => htmlStyleRef.current,
246253
}),
254+
TextShortcutsPlugin.configure({
255+
getTextShortcuts: () => textShortcutsRef.current,
256+
getHtmlStyle: () => htmlStyleRef.current,
257+
}),
247258
AutolinkPlugin.configure({
248259
getLinkEmitter: () => linkEmitterRef.current,
249260
}),

src/web/formats/EnrichedOrderedList.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
1-
import { wrappingInputRule } from '@tiptap/core';
21
import { OrderedList } from '@tiptap/extension-list';
32

43
import { applyWrappingListToSelection } from './applyWrappingListToSelection';
54

6-
const ORDERED_LIST_INPUT_REGEX = /^1\.\s$/;
7-
85
export const EnrichedOrderedList = OrderedList.extend({
9-
addInputRules() {
10-
return [
11-
wrappingInputRule({
12-
find: ORDERED_LIST_INPUT_REGEX,
13-
type: this.type,
14-
}),
15-
];
16-
},
17-
186
addKeyboardShortcuts() {
197
return {};
208
},

src/web/formats/EnrichedUnorderedList.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { wrappingInputRule, type CommandProps } from '@tiptap/core';
1+
import { type CommandProps } from '@tiptap/core';
22
import { BulletList } from '@tiptap/extension-list';
33

44
import { applyWrappingListToSelection } from './applyWrappingListToSelection';
@@ -11,20 +11,9 @@ declare module '@tiptap/core' {
1111
}
1212
}
1313

14-
const BULLET_LIST_INPUT_REGEX = /^\s*-\s$/;
15-
1614
export const EnrichedUnorderedList = BulletList.extend({
1715
name: 'unorderedList',
1816

19-
addInputRules() {
20-
return [
21-
wrappingInputRule({
22-
find: BULLET_LIST_INPUT_REGEX,
23-
type: this.type,
24-
}),
25-
];
26-
},
27-
2817
addKeyboardShortcuts() {
2918
return {};
3019
},

0 commit comments

Comments
 (0)