Файли
openidea/e2e/commentToggle.spec.ts
T
aconeshanaтаaconeshana 2d6394f203 fix(editor): take a JSX block comment back out on the second toggling (#2121)
In a TSX file, a second Comment with Line Comment on a JSX line wrapped `{/* ... */}` in another comment, leaving `/* {/* ... */} */`, which no longer compiles. The comment tokens depend on the syntax node at a position, and the action read them only at the start of the range, so it could never find the comment already around the range.

Both Comment with Line Comment and Comment with Block Comment now read the token pairs at both ends of the range and past its last line, take the widest match, and fall back to CodeMirror only for the wrapping.

Siblings covered: multiple selections on JSX lines, and selections spanning separate comments such as `/* a */ b /* c */`, which are now left unchanged instead of having delimiters removed across live code.

Co-authored-by: aconeshana <[email protected]>
2026-11-08 20:36:07 +08:00

33 рядки
1.1 KiB
TypeScript

import { expect, openFromTree, test } from "./fixtures";
// A JSX comment is `{/* … */}` among JSX children, while its own text parses as
// JavaScript, where the tokens are `/* … */`. Toggling must still take it back out.
const SRC = `export function App() {
return (
<div>
<b>x</b>
</div>
);
}
`;
test("⌘/ twice on a JSX line gives the line back", async ({ workbench: page }) => {
await page.evaluate(async (src) => {
const backendModule = "/src/editor/core/backend.ts";
const mod = await import(/* @vite-ignore */ backendModule);
const backend = mod.docBackend() as { files: Map<string, string> };
backend.files.set("/dev/acme-api/App.tsx", src);
}, SRC);
const editor = await openFromTree(page, "App.tsx");
const content = editor.locator(".cm-content");
await editor.locator(".cm-line", { hasText: "<b>x</b>" }).click();
await page.keyboard.press("Meta+/");
await expect(content).toContainText("{/* <b>x</b> */}");
await page.keyboard.press("Meta+/");
await expect(content).not.toContainText("/*");
await expect(editor.locator(".cm-line", { hasText: "<b>x</b>" })).toHaveText("<b>x</b>");
});