Skip to content

Commit e4a7387

Browse files
TonybynMp4claude
andcommitted
fix(pull-requests): mention completion moves the caret past existing whitespace
Also mocks useDebouncedValue in DiffPanel.browser.test.tsx, which now renders the mention textarea through DiffCommentAnnotation. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 8955225 commit e4a7387

3 files changed

Lines changed: 10 additions & 11 deletions

File tree

‎apps/web/src/components/DiffPanel.browser.test.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ vi.mock("~/hooks/useTheme", () => ({ useRenderedAppearance: () => "dark" }));
7171
vi.mock("~/state/queries", () => ({
7272
useCheckpointDiff: () => ({ data: null, error: null, isPending: false }),
7373
useTurnItemDetail: () => ({ data: null, error: null, isPending: false }),
74+
useDebouncedValue: <A,>(value: A) => value,
7475
}));
7576
vi.mock("~/state/use-atom-command", () => ({ useAtomCommand: () => async () => {} }));
7677
vi.mock("~/editorPreferences", () => ({ useOpenInPreferredEditor: () => async () => {} }));

‎packages/shared/src/pullRequestComposerTrigger.test.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,12 @@ describe("insertPullRequestMention", () => {
4343
});
4444
});
4545

46-
it("reuses the space that already follows", () => {
46+
it("reuses the space that already follows and moves past it", () => {
4747
const text = "@ju please look";
4848
const trigger = detectPullRequestMention(text, 3)!;
49-
expect(insertPullRequestMention(text, trigger, "julius")).toEqual({
50-
text: "@julius please look",
51-
cursor: "@julius".length,
52-
});
49+
const inserted = insertPullRequestMention(text, trigger, "julius");
50+
expect(inserted).toEqual({ text: "@julius please look", cursor: "@julius ".length });
51+
expect(detectPullRequestMention(inserted.text, inserted.cursor)).toBeNull();
5352
});
5453
});
5554

‎packages/shared/src/pullRequestComposerTrigger.ts‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@ export function insertPullRequestMention(
3030
login: string,
3131
): { text: string; cursor: number } {
3232
const followedBySpace = /\s/.test(text[trigger.rangeEnd] ?? "");
33-
return replaceTextRange(
34-
text,
35-
trigger.rangeStart,
36-
trigger.rangeEnd,
37-
followedBySpace ? `@${login}` : `@${login} `,
38-
);
33+
if (!followedBySpace) {
34+
return replaceTextRange(text, trigger.rangeStart, trigger.rangeEnd, `@${login} `);
35+
}
36+
const inserted = replaceTextRange(text, trigger.rangeStart, trigger.rangeEnd, `@${login}`);
37+
return { ...inserted, cursor: inserted.cursor + 1 };
3938
}
4039

4140
// GitLab's project users search answers nothing below three characters, so shorter queries

0 commit comments

Comments
 (0)