Skip to content

Commit 4a7db79

Browse files
Prevent hover hangs outside single-line display math (#1212)
* Prevent hover hangs outside single-line display math * Add CHANGELOG entry --------- Co-authored-by: Julia Silge <julia.silge@gmail.com>
1 parent 4ad2f54 commit 4a7db79

3 files changed

Lines changed: 63 additions & 1 deletion

File tree

‎apps/vscode/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 1.140.0 (Unreleased)
44

5+
- Fixed a bug where the language server could hang when hovering over text on a line that contains single-line display math such as `$$x$$` (<https://github.com/quarto-dev/quarto/pull/1212>).
56
- In the visual editor, the Insert Emoji and Insert Unicode popups no longer close on their own about five seconds after the editor is first focused, which could happen while a search term was still being typed. They now close when the editor is scrolled or focus moves elsewhere within the editor, as do the completion popups for citations, cross references and the `/` insert menu (<https://github.com/quarto-dev/quarto/pull/1204>).
67
- In the visual editor, the equation preview popup now follows its equation again after the window or editor pane is resized. Previously it stayed in place until the next edit or cursor move (<https://github.com/quarto-dev/quarto/pull/1204>).
78
- The outline no longer shows duplicate "Quarto" groups for a document after settings change quickly, for example while VS Code starts (<https://github.com/quarto-dev/quarto/pull/1210>).

‎packages/quarto-core/src/markdown/cursor.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function isLatexCodeBlock(token: Token) {
8787
}
8888

8989
const kInlineMathPattern = /\$([^ ].*?[^ ]?)\$/g;
90-
const kSingleLineDisplayMathPattern = /\$\$([^\n]+?)\$\$/;
90+
const kSingleLineDisplayMathPattern = /\$\$([^\n]+?)\$\$/g;
9191

9292
function inlineMathRange(pos: Position, line: string, pattern: RegExp) {
9393
pattern.lastIndex = 0;
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* cursor.test.ts
3+
*
4+
* Copyright (C) 2026 by Posit Software, PBC
5+
*/
6+
7+
import assert from "node:assert/strict";
8+
import test from "node:test";
9+
import { runInNewContext } from "node:vm";
10+
11+
import { Position, Range } from "vscode-languageserver-types";
12+
13+
import { Document } from "../src/document";
14+
import { mathRange } from "../src/markdown/cursor";
15+
import { markdownitParser } from "../src/markdown/parsers/markdownit";
16+
17+
function document(text: string): Document {
18+
return {
19+
uri: "file:///math.qmd",
20+
languageId: "quarto",
21+
version: 1,
22+
lineCount: 1,
23+
getText: () => text,
24+
positionAt: (offset) => Position.create(0, offset),
25+
};
26+
}
27+
28+
for (const [text, character] of [
29+
["Before $$x$$ after", 0],
30+
["Before $$x$$ after", 16],
31+
["Before $$x$$ and $$y$$ after", 14],
32+
["Before $$x$$ and $$y$$ after", 26],
33+
] as const) {
34+
test(`returns no math at character ${character} in ${JSON.stringify(text)}`, () => {
35+
assert.equal(
36+
runInNewContext(
37+
"mathRange(parser, doc, position)",
38+
{ mathRange, parser: markdownitParser(), doc: document(text), position: Position.create(0, character) },
39+
{ timeout: 1000 }
40+
),
41+
null
42+
);
43+
});
44+
}
45+
46+
test("finds later display math and resets the search for repeated requests", () => {
47+
const parser = markdownitParser();
48+
const doc = document("Before $$x$$ and $$y$$ after");
49+
for (const character of [22, 12, 22, 12]) {
50+
assert.deepEqual(
51+
runInNewContext(
52+
"mathRange(parser, doc, position)",
53+
{ mathRange, parser, doc, position: Position.create(0, character) },
54+
{ timeout: 1000 }
55+
),
56+
character === 22
57+
? { math: "y", range: Range.create(0, 17, 0, 22) }
58+
: { math: "x", range: Range.create(0, 7, 0, 12) }
59+
);
60+
}
61+
});

0 commit comments

Comments
 (0)