Skip to content

Commit 6853658

Browse files
committed
fix(pull-requests): keep completed mentions before line breaks
1 parent 2011268 commit 6853658

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,17 @@ describe("detectPullRequestMention", () => {
3434
});
3535

3636
describe("insertPullRequestMention", () => {
37-
it("replaces the partial login and adds a space", () => {
38-
const text = "thanks @ju";
39-
const trigger = detectPullRequestMention(text, text.length)!;
40-
expect(insertPullRequestMention(text, trigger, "julius")).toEqual({
41-
text: "thanks @julius ",
42-
cursor: "thanks @julius ".length,
43-
});
44-
});
37+
it.each(["", "\nnext line", "\r\nnext line"])(
38+
"replaces the partial login and adds a space before %j",
39+
(suffix) => {
40+
const text = `thanks @ju${suffix}`;
41+
const trigger = detectPullRequestMention(text, "thanks @ju".length)!;
42+
expect(insertPullRequestMention(text, trigger, "julius")).toEqual({
43+
text: `thanks @julius ${suffix}`,
44+
cursor: "thanks @julius ".length,
45+
});
46+
},
47+
);
4548

4649
it("reuses the space that already follows and moves past it", () => {
4750
const text = "@ju please look";

‎packages/shared/src/pullRequestComposerTrigger.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function insertPullRequestMention(
2929
trigger: PullRequestMentionTrigger,
3030
login: string,
3131
): { text: string; cursor: number } {
32-
const followedBySpace = /\s/.test(text[trigger.rangeEnd] ?? "");
32+
const followedBySpace = /[ \t]/.test(text[trigger.rangeEnd] ?? "");
3333
if (!followedBySpace) {
3434
return replaceTextRange(text, trigger.rangeStart, trigger.rangeEnd, `@${login} `);
3535
}

0 commit comments

Comments
 (0)