дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 17:21:13 +02:00
The editor, tool windows and database results painted their selected tab with the same accent, so it wasn't clear which part had focus. A focus-scope tracker now marks the editor pane, each tool window and the results view that contain the focused element; outside the focused scope the selected tab uses the existing --bg-tab-selected-inactive / --border-tab-selected-inactive tokens. Scopes are opt-in, so tab strips in dialogs and popups stay accented, and focus moving into a popup, menu or dialog keeps the current marks. IntelliJ theme import maps the inactive underlined tab colours to the same tokens. Co-authored-by: Mr0Bread <[email protected]>
57 рядки
2.1 KiB
TypeScript
57 рядки
2.1 KiB
TypeScript
import { afterEach, describe, expect, it } from "vitest";
|
|
import { FOCUS_ACTIVE_ATTR, installFocusScopeTracking } from "./focusScope";
|
|
|
|
describe("focus scopes", () => {
|
|
let dispose = () => {};
|
|
afterEach(() => {
|
|
dispose();
|
|
document.body.innerHTML = "";
|
|
});
|
|
|
|
function setup() {
|
|
document.body.innerHTML = `
|
|
<section id="editor" data-focus-scope><button id="editorTab">a</button></section>
|
|
<section id="services" data-focus-scope>
|
|
<button id="tree">tree</button>
|
|
<div id="results" data-focus-scope><button id="grid">grid</button></div>
|
|
</section>
|
|
<div data-popup><button id="menuItem">menu</button></div>`;
|
|
dispose = installFocusScopeTracking();
|
|
const el = (id: string) => document.getElementById(id)!;
|
|
const active = () =>
|
|
["editor", "services", "results"].filter((id) => el(id).hasAttribute(FOCUS_ACTIVE_ATTR)).join(",");
|
|
return { el, active };
|
|
}
|
|
|
|
it("marks the focused scope with its enclosing scopes and moves the mark with focus", () => {
|
|
const { el, active } = setup();
|
|
el("editorTab").focus();
|
|
expect(active()).toBe("editor");
|
|
el("grid").focus();
|
|
expect(active()).toBe("services,results");
|
|
el("tree").focus();
|
|
expect(active()).toBe("services");
|
|
});
|
|
|
|
it("keeps the marks while focus is in a popup or nowhere", () => {
|
|
const { el, active } = setup();
|
|
el("grid").focus();
|
|
el("menuItem").focus();
|
|
expect(active()).toBe("services,results");
|
|
el("menuItem").blur();
|
|
expect(document.activeElement).toBe(document.body);
|
|
expect(active()).toBe("services,results");
|
|
});
|
|
|
|
it("marks the scope already holding focus on install and clears the marks on dispose", () => {
|
|
document.body.innerHTML = `<section id="editor" data-focus-scope><button id="tab">a</button></section>`;
|
|
document.getElementById("tab")!.focus();
|
|
dispose = installFocusScopeTracking();
|
|
const editor = document.getElementById("editor")!;
|
|
expect(editor.hasAttribute(FOCUS_ACTIVE_ATTR)).toBe(true);
|
|
dispose();
|
|
dispose = () => {};
|
|
expect(editor.hasAttribute(FOCUS_ACTIVE_ATTR)).toBe(false);
|
|
});
|
|
});
|