@devries-cameron20 / t3code Mirror · read-only / commits / bb76f1233c
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 23:15 UTC

fix(web): keep typed underscores literal in the rich text composer (#19186)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Scott Norteman committed Oct 20, 2026 at 00:16 UTC bb76f1233c8660399fc72087a5194676d7124cef
5 files changed +66 -2
apps/web/package.json
+1
@@ -45,6 +45,7 @@
45 "@tiptap/extension-code-block": "^3.31.3",
46 "@tiptap/extension-heading": "^3.31.3",
47 "@tiptap/extension-horizontal-rule": "^3.31.3",
48 + "@tiptap/extension-italic": "^3.31.3",
49 "@tiptap/extension-list": "^3.31.3",
50 "@tiptap/extension-task-item": "^3.31.3",
51 "@tiptap/extension-task-list": "^3.31.3",
apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx
+36
@@ -116,6 +116,42 @@ function typeText(editor: Editor, from: number, to: number, text: string) {
116 }
117 }
118
119 +function textWithMark(editor: Editor, name: string) {
120 + const text: string[] = [];
121 + editor.state.doc.descendants((node) => {
122 + if (node.isText && node.marks.some((mark) => mark.type.name === name)) {
123 + text.push(node.textContent);
124 + }
125 + });
126 + return text;
127 +}
128 +
129 +it.each([
130 + { value: "clean _build and node", code: [] },
131 + { value: "clean `_build` and `node", code: ["_build"] },
132 +])("keeps a typed underscore literal after $value", async ({ value, code }) => {
133 + const editor = await mountEditor(value);
134 + await act(async () => {
135 + editor.commands.focus("end");
136 + const { from, to } = editor.state.selection;
137 + typeText(editor, from, to, "_");
138 + });
139 + expect(serializeEditorDoc(editor.state.doc).value).toBe(`${value}_`);
140 + expect(textWithMark(editor, "italic")).toEqual([]);
141 + expect(textWithMark(editor, "code")).toEqual(code);
142 +});
143 +
144 +it("still italicizes text when typing a closing asterisk", async () => {
145 + const editor = await mountEditor("clean *build");
146 + await act(async () => {
147 + editor.commands.focus("end");
148 + const { from, to } = editor.state.selection;
149 + typeText(editor, from, to, "*");
150 + });
151 + expect(serializeEditorDoc(editor.state.doc).value).toBe("clean *build*");
152 + expect(textWithMark(editor, "italic")).toEqual(["build"]);
153 +});
154 +
155 it.each([false, true])(
156 "composes an umlaut without wrapping the preedit text (rich text: %s)",
157 async (richTextEnabled) => {
apps/web/src/components/ComposerPromptEditorTiptap.tsx
+4 -1
@@ -68,6 +68,7 @@ import {
68 caretTakesMarksBefore,
69 convertBulletItemToTask,
70 ComposerCodeExtension,
71 + ComposerItalicExtension,
72 ComposerTaskItemExtension,
73 ComposerTaskListExtension,
74 flatToMarkdown,
@@ -843,7 +844,8 @@ function createComposerExtensions(richText: boolean) {
844 code: false,
845 listKeymap: false,
846 undoRedo: { newGroupDelay: COMPOSER_UNDO_GROUP_DELAY },
846 - ...(richText ? {} : { bold: false, italic: false, strike: false }),
847 + italic: false,
848 + ...(richText ? {} : { bold: false, strike: false }),
849 }),
850 ComposerUndoGroupingExtension,
851 ComposerMentionExtension,
@@ -853,6 +855,7 @@ function createComposerExtensions(richText: boolean) {
855 ComposerMarkersExtension,
856 ...(richText
857 ? [
858 + ComposerItalicExtension,
859 ComposerCodeExtension,
860 ComposerCodeBlockExtension.extend({
861 addNodeView() {
apps/web/src/composer-rich-text-doc.ts
+22 -1
@@ -11,7 +11,14 @@ import { Blockquote } from "@tiptap/extension-blockquote";
11 import { CodeBlock } from "@tiptap/extension-code-block";
12 import { Heading } from "@tiptap/extension-heading";
13 import { HorizontalRule } from "@tiptap/extension-horizontal-rule";
14 -import { type Command, type Editor, mergeAttributes } from "@tiptap/core";
14 +import { Italic, starInputRegex, starPasteRegex } from "@tiptap/extension-italic";
15 +import {
16 + type Command,
17 + type Editor,
18 + markInputRule,
19 + markPasteRule,
20 + mergeAttributes,
21 +} from "@tiptap/core";
22 import { BulletList, ListItem, OrderedList } from "@tiptap/extension-list";
23 import { TaskItem } from "@tiptap/extension-task-item";
24 import { TaskList } from "@tiptap/extension-task-list";
@@ -127,6 +134,20 @@ export const ComposerCodeExtension = Code.extend({
134 },
135 });
136
137 +/**
138 + * The composer writes italic as `*text*`, so it keeps only the `*` shortcuts.
139 + * Tiptap's `_text_` rules fire on the `_` in names like `node_modules` and
140 + * italicize back to an earlier `_build`, even one inside a code span.
141 + */
142 +export const ComposerItalicExtension = Italic.extend({
143 + addInputRules() {
144 + return [markInputRule({ find: starInputRegex, type: this.type })];
145 + },
146 + addPasteRules() {
147 + return [markPasteRule({ find: starPasteRegex, type: this.type })];
148 + },
149 +});
150 +
151 /**
152 * Tiptap's block extensions each bind a chord that turns the current block into
153 * their node (Mod-Shift-8 for a list, Mod-Alt-c for a fence, and so on). The
pnpm-lock.yaml
+3
@@ -907,6 +907,9 @@ importers:
907 '@tiptap/extension-horizontal-rule':
908 specifier: ^3.31.3
909 version: 3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))(@tiptap/pm@3.31.3)
910 + '@tiptap/extension-italic':
911 + specifier: ^3.31.3
912 + version: 3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))
913 '@tiptap/extension-list':
914 specifier: ^3.31.3
915 version: 3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))(@tiptap/pm@3.31.3)