@devries-cameron20 / t3code Mirror · read-only / commits / 213b39198f
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, 09:30 UTC

fix(web): composer emphasis shortcuts ignore delimiters inside inline code (#25659)

Co-authored-by: maria-rcks <maria@kuuro.net>

Ege Feyzioglu committed Oct 31, 2026 at 22:33 UTC 213b39198f799a9b2c8536dc760ab5008dd7aeed
5 files changed +140 -3
apps/web/package.json
+2
@@ -41,12 +41,14 @@
41 "@tanstack/react-router": "^1.160.2",
42 "@tiptap/core": "^3.31.3",
43 "@tiptap/extension-blockquote": "^3.31.3",
44 + "@tiptap/extension-bold": "^3.31.3",
45 "@tiptap/extension-code": "^3.31.3",
46 "@tiptap/extension-code-block": "^3.31.3",
47 "@tiptap/extension-heading": "^3.31.3",
48 "@tiptap/extension-horizontal-rule": "^3.31.3",
49 "@tiptap/extension-italic": "^3.31.3",
50 "@tiptap/extension-list": "^3.31.3",
51 + "@tiptap/extension-strike": "^3.31.3",
52 "@tiptap/extension-task-item": "^3.31.3",
53 "@tiptap/extension-task-list": "^3.31.3",
54 "@tiptap/pm": "^3.31.3",
apps/web/src/components/ComposerPromptEditorTiptap.tsx
+6 -1
@@ -73,7 +73,9 @@ import {
73 ComposerBoldSelectionOnlyExtension,
74 convertBulletItemToTask,
75 ComposerCodeExtension,
76 + ComposerBoldExtension,
77 ComposerItalicExtension,
78 + ComposerStrikeExtension,
79 ComposerTaskItemExtension,
80 ComposerTaskListExtension,
81 flatToMarkdown,
@@ -831,7 +833,8 @@ function createComposerExtensions(richText: boolean) {
833 listKeymap: false,
834 undoRedo: { newGroupDelay: COMPOSER_UNDO_GROUP_DELAY },
835 italic: false,
834 - ...(richText ? {} : { bold: false, strike: false }),
836 + bold: false,
837 + strike: false,
838 }),
839 ComposerUndoGroupingExtension,
840 ComposerTextDirectionExtension,
@@ -844,6 +847,8 @@ function createComposerExtensions(richText: boolean) {
847 ? [
848 ComposerBoldSelectionOnlyExtension,
849 ComposerItalicExtension,
850 + ComposerBoldExtension,
851 + ComposerStrikeExtension,
852 ComposerCodeExtension,
853 ComposerCodeBlockExtension.extend({
854 addNodeView() {
apps/web/src/composer-rich-text-doc.test.ts
+80 -1
@@ -20,7 +20,10 @@ import {
20 ComposerBlockExtensions,
21 ComposerCodeBlockExtension,
22 ComposerListExtensions,
23 + ComposerBoldExtension,
24 ComposerCodeExtension,
25 + ComposerItalicExtension,
26 + ComposerStrikeExtension,
27 ComposerTaskItemExtension,
28 flatToMarkdown,
29 flatToPm,
@@ -1003,7 +1006,17 @@ describe("inline code entry", () => {
1006 const editor = new Editor({
1007 element: null,
1008 extensions: [
1006 - StarterKit.configure({ code: false, codeBlock: false, trailingNode: false }),
1009 + StarterKit.configure({
1010 + bold: false,
1011 + code: false,
1012 + codeBlock: false,
1013 + italic: false,
1014 + strike: false,
1015 + trailingNode: false,
1016 + }),
1017 + ComposerBoldExtension,
1018 + ComposerItalicExtension,
1019 + ComposerStrikeExtension,
1020 ComposerCodeExtension,
1021 ComposerCodeBlockExtension,
1022 stubAtom("composer-mention", { path: { default: "" }, source: { default: "" } }),
@@ -1165,4 +1178,70 @@ describe("inline code entry", () => {
1178 editor.commands.setTextSelection(editor.state.doc.content.size - 1);
1179 expect(editor.state.doc.toJSON()).toEqual(before);
1180 });
1181 +
1182 + function marked(editor: Editor, name: string) {
1183 + const text: string[] = [];
1184 + editor.state.doc.descendants((node) => {
1185 + if (node.isText && node.marks.some((mark) => mark.type.name === name)) {
1186 + text.push(node.text ?? "");
1187 + }
1188 + });
1189 + return text;
1190 + }
1191 +
1192 + /** Types `text` into a backtick pair and steps the caret out so it formats. */
1193 + function typeCode(editor: Editor, text: string) {
1194 + const offset = editor.state.selection.from;
1195 + type(editor, "``");
1196 + editor.commands.setTextSelection(offset + 1);
1197 + type(editor, text);
1198 + editor.commands.setTextSelection(offset + text.length + 2);
1199 + expect(marked(editor, "code")).toContain(text);
1200 + }
1201 +
1202 + it.each([
1203 + { mark: "italic", open: "*" },
1204 + { mark: "bold", open: "**" },
1205 + { mark: "strike", open: "~~" },
1206 + ])("keeps a $mark delimiter inside an earlier code span literal", ({ mark, open }) => {
1207 + const editor = editorFor();
1208 + typeCode(editor, `${open}foo`);
1209 + type(editor, ` bar \`${open}`);
1210 + expect(serializeEditorDoc(editor.state.doc).value).toBe(`\`${open}foo\` bar \`${open}`);
1211 + expect(marked(editor, mark)).toEqual([]);
1212 + expect(marked(editor, "code")).toEqual([`${open}foo`]);
1213 + });
1214 +
1215 + it.each([
1216 + { mark: "italic", open: "*" },
1217 + { mark: "bold", open: "**" },
1218 + { mark: "strike", open: "~~" },
1219 + ])("still wraps a code span in $mark when both delimiters are outside it", ({ mark, open }) => {
1220 + const editor = editorFor();
1221 + type(editor, open);
1222 + typeCode(editor, "foo");
1223 + type(editor, ` bar${open}`);
1224 + expect(serializeEditorDoc(editor.state.doc).value).toBe(`${open}\`foo\` bar${open}`);
1225 + expect(marked(editor, mark)).toEqual(["foo", " bar"]);
1226 +
1227 + editor.commands.setContent({
1228 + type: "doc",
1229 + content: [
1230 + {
1231 + type: "paragraph",
1232 + content: [
1233 + { type: "text", text: `${open}foo tail ` },
1234 + { type: "text", text: "x", marks: [{ type: "code" }] },
1235 + ],
1236 + },
1237 + ],
1238 + });
1239 + editor.commands.setTextSelection({
1240 + from: open.length + 4,
1241 + to: editor.state.doc.content.size - 1,
1242 + });
1243 + type(editor, open);
1244 + expect(serializeEditorDoc(editor.state.doc).value).toBe(`${open}foo${open}`);
1245 + expect(marked(editor, mark)).toEqual(["foo"]);
1246 + });
1247 });
apps/web/src/composer-rich-text-doc.ts
+46 -1
@@ -6,6 +6,11 @@ import {
6 type Node as ProseMirrorNode,
7 type ResolvedPos,
8 } from "@tiptap/pm/model";
9 +import {
10 + Bold,
11 + starInputRegex as boldStarInputRegex,
12 + underscoreInputRegex as boldUnderscoreInputRegex,
13 +} from "@tiptap/extension-bold";
14 import { Code } from "@tiptap/extension-code";
15 import { Blockquote } from "@tiptap/extension-blockquote";
16 import { CodeBlock } from "@tiptap/extension-code-block";
@@ -16,11 +21,13 @@ import {
21 type Command,
22 type Editor,
23 Extension,
24 + InputRule,
25 markInputRule,
26 markPasteRule,
27 mergeAttributes,
28 } from "@tiptap/core";
29 import { BulletList, ListItem, OrderedList } from "@tiptap/extension-list";
30 +import { Strike, inputRegex as strikeInputRegex } from "@tiptap/extension-strike";
31 import { TaskItem } from "@tiptap/extension-task-item";
32 import { TaskList } from "@tiptap/extension-task-list";
33 import {
@@ -163,6 +170,29 @@ export const ComposerCodeExtension = Code.extend({
170 },
171 });
172
173 +// Code permits nested emphasis, so Tiptap's exclusion check cannot protect literal delimiters.
174 +function markInputRuleOutsideCode(find: RegExp, type: MarkType) {
175 + const rule = markInputRule({ find, type });
176 + return new InputRule({
177 + find,
178 + handler: (props) => {
179 + const { state, range, match } = props;
180 + const code = state.schema.marks.code;
181 + const content = match[match.length - 1] ?? "";
182 + const textStart = range.from + match[0].indexOf(content);
183 + const textEnd = textStart + content.length;
184 + if (
185 + code &&
186 + (state.doc.rangeHasMark(range.from + match[0].search(/\S/), textStart, code) ||
187 + state.doc.rangeHasMark(textEnd, state.selection.from, code))
188 + ) {
189 + return null;
190 + }
191 + return rule.handler(props);
192 + },
193 + });
194 +}
195 +
196 /**
197 * The composer writes italic as `*text*`, so it keeps only the `*` shortcuts.
198 * Tiptap's `_text_` rules fire on the `_` in names like `node_modules` and
@@ -170,13 +200,28 @@ export const ComposerCodeExtension = Code.extend({
200 */
201 export const ComposerItalicExtension = Italic.extend({
202 addInputRules() {
173 - return [markInputRule({ find: starInputRegex, type: this.type })];
203 + return [markInputRuleOutsideCode(starInputRegex, this.type)];
204 },
205 addPasteRules() {
206 return [markPasteRule({ find: starPasteRegex, type: this.type })];
207 },
208 });
209
210 +export const ComposerBoldExtension = Bold.extend({
211 + addInputRules() {
212 + return [
213 + markInputRuleOutsideCode(boldStarInputRegex, this.type),
214 + markInputRuleOutsideCode(boldUnderscoreInputRegex, this.type),
215 + ];
216 + },
217 +});
218 +
219 +export const ComposerStrikeExtension = Strike.extend({
220 + addInputRules() {
221 + return [markInputRuleOutsideCode(strikeInputRegex, this.type)];
222 + },
223 +});
224 +
225 /**
226 * Mod+B bolds selected text only. Without a selection Tiptap would toggle bold
227 * for the next typed text, which users hit by accident when they mean the
pnpm-lock.yaml
+6
@@ -1094,6 +1094,9 @@ importers:
1094 '@tiptap/extension-blockquote':
1095 specifier: ^3.31.3
1096 version: 3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))(@tiptap/pm@3.31.3)
1097 + '@tiptap/extension-bold':
1098 + specifier: ^3.31.3
1099 + version: 3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))
1100 '@tiptap/extension-code':
1101 specifier: ^3.31.3
1102 version: 3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))
@@ -1112,6 +1115,9 @@ importers:
1115 '@tiptap/extension-list':
1116 specifier: ^3.31.3
1117 version: 3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))(@tiptap/pm@3.31.3)
1118 + '@tiptap/extension-strike':
1119 + specifier: ^3.31.3
1120 + version: 3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))
1121 '@tiptap/extension-task-item':
1122 specifier: ^3.31.3
1123 version: 3.31.3(@tiptap/extension-list@3.31.3(@tiptap/core@3.31.3(@tiptap/pm@3.31.3))(@tiptap/pm@3.31.3))