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 21, 21:00 UTC
fix(web): Mod+B toggles bold at a collapsed cursor when the sidebar toggle is remapped (#29445)
Julius Marminge committed
Nov 11, 2026 at 16:17 UTC
2904fea7d593c687393b7ad2434de03d590871cd
5 files changed
+61
-27
apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx
+46
-5
@@ -151,6 +151,51 @@ it.each([
151
expect(textWithMark(editor, "code")).toEqual(code);
152
});
153
154
+it.each([
155
+ { mark: "bold", key: "b", marker: "**" },
156
+ { mark: "italic", key: "i", marker: "*" },
157
+])("toggles $mark with Mod+$key at a collapsed cursor", async ({ mark, key, marker }) => {
158
+ await using screen = await mountEditor("ship it");
159
+ const { editor } = screen;
160
+ const mod = isMacPlatform(navigator.platform) ? "Meta" : "Control";
161
+ const chord = `{${mod}>}${key}{/${mod}}`;
162
+ await act(async () => {
163
+ editor.commands.focus("end");
164
+ });
165
+ await vi.waitFor(() => expect(document.activeElement).toBe(editor.view.dom));
166
+ await userEvent.keyboard(" ");
167
+ await userEvent.keyboard(chord);
168
+ await userEvent.keyboard("now");
169
+ await userEvent.keyboard(chord);
170
+ await userEvent.keyboard(" done");
171
+ await vi.waitFor(() =>
172
+ expect(serializeEditorDoc(editor.state.doc).value).toBe(`ship it ${marker}now${marker} done`),
173
+ );
174
+ expect(textWithMark(editor, mark)).toEqual(["now"]);
175
+});
176
+
177
+it.each([
178
+ { key: "i", caret: 10, expected: "ship it **n*X*ow** done" },
179
+ { key: "i", caret: 9, expected: "ship it *X***now** done" },
180
+ { key: "e", caret: "{ArrowLeft>5/}", expected: "ship it **now**`X` done" },
181
+])(
182
+ "Mod+$key at $caret in a bold word styles the next typed text",
183
+ async ({ key, caret, expected }) => {
184
+ await using screen = await mountEditor("ship it **now** done");
185
+ const { editor } = screen;
186
+ const mod = isMacPlatform(navigator.platform) ? "Meta" : "Control";
187
+ await act(async () => {
188
+ if (typeof caret === "number") editor.commands.focus(caret);
189
+ else editor.commands.focus("end");
190
+ });
191
+ await vi.waitFor(() => expect(document.activeElement).toBe(editor.view.dom));
192
+ if (typeof caret === "string") await userEvent.keyboard(caret);
193
+ await userEvent.keyboard(`{${mod}>}${key}{/${mod}}`);
194
+ await userEvent.keyboard("X");
195
+ await vi.waitFor(() => expect(serializeEditorDoc(editor.state.doc).value).toBe(expected));
196
+ },
197
+);
198
+
199
it.each([
200
{ word: "ship", prefix: "", source: ["**ship**"] },
201
{ word: "path\\", prefix: "", source: [] },
@@ -169,7 +214,7 @@ it.each([
214
code: ["path\\"],
215
},
216
])(
172
- "bolds $word after '$prefix' with Mod+B only when text is selected",
217
+ "bolds $word after '$prefix' with Mod+B over a selection",
218
async ({ word, prefix, prefixText = prefix, source, code = [] }) => {
219
const value = `${prefix}${word} it`;
220
await using screen = await mountEditor(value);
@@ -179,10 +224,6 @@ it.each([
224
editor.commands.focus("end");
225
});
226
await vi.waitFor(() => expect(document.activeElement).toBe(editor.view.dom));
182
- await userEvent.keyboard(modB);
183
- // Without the guard, Tiptap stores bold for the next typed text.
184
- expect(editor.state.storedMarks).toBeNull();
185
-
227
await act(async () => {
228
editor.commands.setTextSelection({
229
from: prefixText.length + 1,
apps/web/src/components/ComposerPromptEditorTiptap.tsx
-2
@@ -76,7 +76,6 @@ import {
76
ComposerCodeBlockExtension,
77
ComposerListExtensions,
78
buildTiptapContent,
79
- ComposerBoldSelectionOnlyExtension,
79
convertBulletItemToTask,
80
ComposerCodeExtension,
81
ComposerBoldExtension,
@@ -834,7 +833,6 @@ function createComposerExtensions(richText: boolean) {
833
...(richText
834
? [
835
ComposerMarkdownSourceExtension,
837
- ComposerBoldSelectionOnlyExtension,
836
ComposerItalicExtension,
837
ComposerBoldExtension,
838
ComposerStrikeExtension,
apps/web/src/composer-markdown-source.ts
+14
-4
@@ -550,10 +550,20 @@ export const ComposerMarkdownSourceExtension = TiptapMark.create({
550
// in another style. Parse the source first and toggle the result.
551
const toggle = (name: RichTextMark) => () => {
552
const { state } = this.editor;
553
- if (state.selection.empty) return false;
554
- const touched = sourceRegions(state.doc, this.type).some((region) =>
555
- touches(state.selection, region),
556
- );
553
+ const { selection } = state;
554
+ const touched = sourceRegions(state.doc, this.type).some((region) => {
555
+ if (!touches(selection, region)) return false;
556
+ if (!selection.empty) return true;
557
+ // Turning a style off just inside its own markers would type into them.
558
+ // Everywhere else Tiptap's own toggle styles the typed text correctly.
559
+ const { units } = regionUnits(state.doc, region);
560
+ const offset = selection.from - region.from;
561
+ const [before, after] = [units[offset - 1], units[offset]];
562
+ return (
563
+ (before === null && after?.includes(name) === true) ||
564
+ (after === null && before?.includes(name) === true)
565
+ );
566
+ });
567
if (!touched) return false;
568
return this.editor.chain().command(collapseShownMarkdownSource).toggleMark(name).run();
569
};
apps/web/src/composer-rich-text-doc.ts
-15
@@ -22,7 +22,6 @@ import {
22
getChangedRanges,
23
type Command,
24
type Editor,
25
- Extension,
25
InputRule,
26
markInputRule,
27
markPasteRule,
@@ -372,20 +371,6 @@ export const ComposerStrikeExtension = Strike.extend({
371
},
372
});
373
375
-/**
376
- * Mod+B bolds selected text only. Without a selection Tiptap would toggle bold
377
- * for the next typed text, which users hit by accident when they mean the
378
- * sidebar toggle. Runs ahead of the Bold extension and swallows the chord.
379
- */
380
-export const ComposerBoldSelectionOnlyExtension = Extension.create({
381
- name: "composerBoldSelectionOnly",
382
- priority: 1000,
383
- addKeyboardShortcuts() {
384
- const ignoreWithoutSelection = () => this.editor.state.selection.empty;
385
- return { "Mod-b": ignoreWithoutSelection, "Mod-B": ignoreWithoutSelection };
386
- },
387
-});
388
-
374
/**
375
* Tiptap's block chords can nest blocks inside quotes that the serializer cannot write,
376
* silently dropping their text from stored drafts.
apps/web/src/keybindings.ts
+1
-1
@@ -379,7 +379,7 @@ export function isOpenFavoriteEditorShortcut(
379
* Whether the keypress should bold text in the rich-text composer: Mod+B
380
* without extra modifiers, with text selected. Tiptap binds the same chord, so
381
* app shortcuts captured ahead of the editor yield only in that case. With no
382
- * selection the chord stays with the app (the sidebar toggle by default).
382
+ * selection an app binding on the chord wins (the sidebar toggle by default).
383
*/
384
export function isRichTextBoldShortcut(
385
event: ShortcutEventLike,