Compare commits

...
Author SHA1 Message Date
l0ng-ai 6e61e3d71d fix(vcs): keep F7 working in the diff it opens for the next file
F7 / Shift+F7 past the last difference opened the neighbouring file, but focus landed on the
editor tab's host instead of the diff, so the diff's keymap no longer applied and the next
Shift+F7 did nothing. It only worked before because a stale navigator stayed registered, which
#3137 rightly stopped. The diff now hands the host's focus on to its focused pane, as the image
and hex viewers do.

Also makes main's CI pass again: the htmlFrame test sent the frame's "ready" message before the
listener's effect could run on a slow runner, and the diagnostics fixture needed cargo fmt.
2026-11-14 09:00:35 +08:00
3 changed files with 32 additions and 17 deletions

No files matched your search

+2 -6
View File
@@ -39,12 +39,8 @@ impl Plugin for Fixture {
hover: None,
after: Some(after.into()),
};
host::set_decorations(
path,
"fixture",
&[item("typo", "typo message"), item("weak", "weak message")],
)
.map(|()| None)
host::set_decorations(path, "fixture", &[item("typo", "typo message"), item("weak", "weak message")])
.map(|()| None)
}
_ => Err(Error::NotFound(id.into())),
}
@@ -25,19 +25,23 @@ describe("html bodies in the app", () => {
expect(frame.getAttribute("sandbox")).toBe("allow-scripts");
const post = vi.spyOn(frame.contentWindow!, "postMessage");
// Not from the frame: ignored.
window.dispatchEvent(new MessageEvent("message", { data: { tag: FRAME_TAG, ready: true }, source: window }));
expect(post).not.toHaveBeenCalled();
window.dispatchEvent(
new MessageEvent("message", { data: { tag: FRAME_TAG, ready: true }, source: frame.contentWindow }),
);
expect(post).toHaveBeenCalledWith(
{ tag: FRAME_TAG, document: expect.stringContaining("<p>chart</p><script>draw()</script>") },
"*",
);
const ready = (source: Window | null) =>
window.dispatchEvent(new MessageEvent("message", { data: { tag: FRAME_TAG, ready: true }, source }));
// The listener is added in an effect that can run after the frame is in the DOM.
await waitFor(() => {
ready(frame.contentWindow);
expect(post).toHaveBeenCalledWith(
{ tag: FRAME_TAG, document: expect.stringContaining("<p>chart</p><script>draw()</script>") },
"*",
);
});
const doc = (post.mock.calls[0]![0] as { document: string }).document;
expect(doc).toContain('<meta http-equiv="Content-Security-Policy"');
expect(doc).toContain("window.openidea");
// Not from the frame: ignored.
post.mockClear();
ready(window);
expect(post).not.toHaveBeenCalled();
});
});
+15
View File
@@ -680,6 +680,21 @@ export function DiffEditor({
useEffect(() => viewsRef.current?.panes?.setSync(opts.syncScroll), [opts.syncScroll]);
// The editor area focuses the tab's host (`[data-editor-focus]`), e.g. after F7 opened the next
// file: hand that focus on to the diff, so its keymap and Jump to Source apply right away.
useEffect(() => {
const host = rootRef.current?.closest<HTMLElement>("[data-editor-focus]");
const views = viewsRef.current;
if (!host || !views) return;
const forward = () => (focusedSide.current === "a" && views.a ? views.a : views.b).focus();
const onFocus = (e: FocusEvent) => {
if (e.target === host) forward();
};
host.addEventListener("focus", onFocus);
if (document.activeElement === host) forward();
return () => host.removeEventListener("focus", onFocus);
}, [viewsGen]);
useEffect(
() => () => {
viewsRef.current?.destroy();