Compare commits

...
Author SHA1 Message Date
l0ng-ai 4f755d55de test(e2e): wait for the Run window to take focus before toggling it
The tool-window shortcut hides a window only once it is active, and
activation focuses it on the next frame. Under load the test pressed ⌘4 or
Shift+Escape before that, so the window stayed open.
2026-11-21 04:26:44 +08:00
l0ng-ai 97f78908a1 fix(terminal): don't take focus that moved elsewhere while the view loaded (#4899)
A focus request made before xterm opened was applied whenever it opened, so a terminal still loading took the caret back from a view the user had clicked meanwhile. The deferred focus now applies only while focus is where it was when requested, on the page, or inside the terminal's own tool window.
2026-11-21 04:23:06 +08:00
faysouandfaysou e7aec17d46 Match backtick runs in protected inline Markdown math (#4895)
Protected inline math ($`...`$) now matches the opening backtick run to the first closing run of the same length, as Markdown code spans do: ($``x` + y``$) renders as math, while ($`x` `y`$) keeps two code spans and literal dollars.

Co-authored-by: faysou <[email protected]>

Co-authored-by: faysou <[email protected]>
2026-11-21 03:56:06 +08:00
l0ng-ai cb24f252c5 fix(vcs): keep focus on the commit message when the Commit window opens (#4896)
Activating a tool window focuses its first field or tree on the next frame unless its content marks a data-autofocus target. The Commit window's message wasn't marked, so after Cmd+K focused the message, activation could move focus to the Changes tree depending on timing. The message is now the window's preferred focus, also when the window is activated from its stripe button.
2026-11-21 03:55:28 +08:00
6 changed files with 80 additions and 5 deletions

No files matched your search

+5
View File
@@ -71,12 +71,17 @@ test("⌘1 focuses, hides and re-shows the Project tool window", async ({ workbe
test("⌘4 toggles Run; Shift+Escape hides the active tool window", async ({ workbench: page }) => {
const run = page.getByRole("region", { name: "Run" });
// The shortcut hides the window only once it is active: activation focuses it a frame after it shows.
const focusedInRun = () =>
expect.poll(() => page.evaluate(() => !!document.activeElement?.closest('[data-toolwindow="run"]'))).toBe(true);
await page.keyboard.press("Meta+4");
await expect(run).toBeVisible();
await focusedInRun();
await page.keyboard.press("Meta+4");
await expect(run).toBeHidden();
await page.keyboard.press("Meta+4");
await expect(run).toBeVisible();
await focusedInRun();
await page.keyboard.press("Shift+Escape");
await expect(run).toBeHidden();
});
+11
View File
@@ -37,6 +37,17 @@ describe("markdown LaTeX math", () => {
expect(root.querySelector("p")?.textContent?.startsWith("Prices $5 and $10, with ")).toBe(true);
});
it("leaves separate code spans inside dollar signs as code", () => {
const root = parseSafe("($`x` `y`$)");
expect(root.querySelector("p")?.innerHTML).toBe("($<code>x</code> <code>y</code>$)");
});
it("matches a longer backtick delimiter around math inside emphasis", () => {
const root = parseSafe("**($``x` + y``$)**");
expect(root.querySelector("strong .katex annotation")?.textContent).toBe("x` + y");
expect(root.querySelector("code")).toBeNull();
});
it("keeps an unfinished protected delimiter from swallowing a later formula", () => {
const root = parseSafe("Unfinished $`x` and $y$.");
expect(root.querySelector("p > code")?.textContent).toBe("x");
+4 -3
View File
@@ -39,9 +39,10 @@ function findClosingDelimiter(src: string, from: number, delim: string): number
return -1;
}
const PROTECTED_INLINE_DOLLAR = /^\$`([^`\r\n]+)`\$/;
// The first backtick run of the opening length ends the code span.
const PROTECTED_INLINE_DOLLAR = /^\$(?<ticks>`+)(?!`)(?<tex>(?:[^`\r\n]|(?!\k<ticks>(?!`))`+(?!`))+)\k<ticks>\$/;
// Marked masks code spans as `[aaa]` before calling emStrongMask
const MASKED_PROTECTED_INLINE_DOLLAR = /^\$\[(a+)\]\$/;
const MASKED_PROTECTED_INLINE_DOLLAR = /^\$\[(?<tex>a+)\]\$/;
/**
* Matches inline `$...$` from index 0 using Pandoc-style guards so currency
@@ -87,7 +88,7 @@ function matchInlineMath(
if (src[0] === "$") {
const match = protectedDollar.exec(src);
if (match) {
const text = match[1]!;
const text = match.groups!.tex!;
return text.trim() ? { raw: match[0], text, display: false } : null;
}
if (src[1] === "`") return null;
+45
View File
@@ -422,6 +422,51 @@ describe("terminal open", () => {
});
});
describe("deferred terminal focus", () => {
function openable(key: string) {
const container = document.createElement("div");
document.body.appendChild(container);
const session = new TerminalSession({ key, cwd: "/tmp", onChange: () => undefined, onFocus: () => undefined });
Object.defineProperty(session.host, "offsetWidth", { configurable: true, get: () => 400 });
Object.defineProperty(session.host, "offsetHeight", { configurable: true, get: () => 300 });
const textarea = document.createElement("textarea");
vi.spyOn(session.term, "open").mockImplementation(() => undefined);
Object.defineProperty(session.term, "textarea", { configurable: true, get: () => textarea });
const focus = vi.spyOn(session.term, "focus").mockImplementation(() => undefined);
return { container, session, focus };
}
afterEach(() => vi.useRealTimers());
it("takes the caret once xterm opens when focus stayed put", () => {
vi.useFakeTimers();
const { container, session, focus } = openable("s-stay");
session.focus();
session.attach(container);
vi.advanceTimersByTime(FIT_SETTLE_MS);
expect(focus).toHaveBeenCalledTimes(1);
session.dispose();
container.remove();
});
it("leaves focus that moved elsewhere before xterm opened", () => {
vi.useFakeTimers();
const { container, session, focus } = openable("s-moved");
const tree = document.createElement("div");
tree.tabIndex = 0;
document.body.appendChild(tree);
session.focus();
tree.focus();
session.attach(container);
vi.advanceTimersByTime(FIT_SETTLE_MS);
expect(focus).not.toHaveBeenCalled();
expect(document.activeElement).toBe(tree);
session.dispose();
container.remove();
tree.remove();
});
});
describe("terminal font zoom", () => {
afterEach(() => {
unbindTerminals();
+14 -1
View File
@@ -254,6 +254,8 @@ export class TerminalSession {
private opened = false;
/** `focus()` arrived before the textarea existed (the pane is focused while xterm is still closed). */
private pendingFocus = false;
/** What had focus when `pendingFocus` was set: a later move elsewhere cancels it. */
private pendingFocusFrom: Element | null = null;
/** Bounds retries when the pane has no box yet, or xterm cannot measure a cell. */
private fitAttempts = 0;
private disposed = false;
@@ -679,7 +681,17 @@ export class TerminalSession {
this.opts.onFocus(this.key);
});
this.watchImeCommit();
if (this.pendingFocus) this.focus();
if (this.pendingFocus) {
this.pendingFocus = false;
if (this.focusStayedHere()) this.focus();
}
}
/** Whether focus is still where the deferred `focus()` left it, or in this terminal's own window. */
private focusStayedHere(): boolean {
const active = document.activeElement;
if (!active || active === document.body || active === this.pendingFocusFrom) return true;
return this.host.contains(active) || !!this.host.closest("[data-toolwindow]")?.contains(active);
}
detach(container: HTMLElement) {
@@ -990,6 +1002,7 @@ export class TerminalSession {
this.clearUnseenDone();
if (!this.opened || !this.term.textarea) {
this.pendingFocus = true;
this.pendingFocusFrom = document.activeElement;
this.scheduleFit();
return;
}
+1 -1
View File
@@ -1330,7 +1330,7 @@ function CommitPanel({ included }: { included: number }) {
return (
<div className={styles.commit}>
<CommitMessageField included={included} runner={runner} />
<CommitMessageField included={included} runner={runner} autoFocus />
<div className={styles.commitActions}>
<Button variant="primary" disabled={!canCommit} onClick={() => void runner.run(false)} title="⌘↩">
<T>{commitLabel(amend, checkProblems.length > 0, commitAll)}</T>