fix(app): prevent infinite loop in @-mention scan when @ is at index 0
`findActiveFileMention` walked back through `@` candidates with
`lastIndexOf("@", atIndex - 1)`, but per spec a negative `position`
clamps to 0 — so once `atIndex` hit 0 with an invalid query (e.g. a
trailing space), the loop stepped from 0 back to 0 forever, freezing
the JS thread on every keystroke and forcing a quit.
Refs #596, #425
This commit is contained in:
@@ -36,6 +36,14 @@ describe("findActiveFileMention", () => {
|
||||
});
|
||||
expect(mention).toBeNull();
|
||||
});
|
||||
|
||||
it("returns null when @ at start is followed by a delimiter", () => {
|
||||
const mention = findActiveFileMention({
|
||||
text: "@ ",
|
||||
cursorIndex: 2,
|
||||
});
|
||||
expect(mention).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("applyFileMentionReplacement", () => {
|
||||
|
||||
@@ -24,7 +24,7 @@ export function findActiveFileMention(input: FindActiveFileMentionInput): FileMe
|
||||
for (
|
||||
let atIndex = beforeCursor.lastIndexOf("@");
|
||||
atIndex >= 0;
|
||||
atIndex = beforeCursor.lastIndexOf("@", atIndex - 1)
|
||||
atIndex = atIndex === 0 ? -1 : beforeCursor.lastIndexOf("@", atIndex - 1)
|
||||
) {
|
||||
const query = beforeCursor.slice(atIndex + 1);
|
||||
if (INVALID_MENTION_QUERY_CHARS.test(query)) {
|
||||
|
||||
Reference in New Issue
Block a user