дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-29 13:52:36 +02:00
fix(editor): keep the keyboard in the editor after closing the focused tab
Closing the focused editor tab (⌘W) showed the next tab but left the keyboard focus on the page body, so arrow keys and typing did nothing until the editor was clicked. The tab that takes its place now gets the focus when the closed one had it.
Цей коміт міститься в:
1 джерело
83364c5423
коміт
0ee28f7783
2 files changed
+35
-2
No files matched your search
@@ -203,6 +203,29 @@ describe("EditorController", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("gives the keyboard to the next tab when the focused one closes", async () => {
|
||||
ctrl = new EditorController(createMemoryBackend({ "/p/a.ts": "a\n", "/p/b.ts": "b\n" }));
|
||||
ctrl.start();
|
||||
await ctrl.openFile("/p/a.ts", { focus: false });
|
||||
const first = ctrl.activeSlot!;
|
||||
await ctrl.openFile("/p/b.ts", { focus: false });
|
||||
const second = ctrl.activeSlot!;
|
||||
const hosts = [document.createElement("div"), document.createElement("div")];
|
||||
document.body.append(...hosts);
|
||||
try {
|
||||
const a = first.mount(hosts[0]!);
|
||||
ctrl.onMounted(first);
|
||||
const b = second.mount(hosts[1]!);
|
||||
ctrl.onMounted(second);
|
||||
b.focus();
|
||||
expect(b.hasFocus).toBe(true);
|
||||
await ctrl.closeActiveTab();
|
||||
expect(a.hasFocus).toBe(true);
|
||||
} finally {
|
||||
hosts.forEach((h) => h.remove());
|
||||
}
|
||||
});
|
||||
|
||||
it("autosaves on blur, but not while focus is in a popup over the editor", async () => {
|
||||
const backend = createMemoryBackend({ "/p/a.c": "int main() {\n \n}\n" });
|
||||
const save = vi.spyOn(backend, "save");
|
||||
|
||||
@@ -1735,8 +1735,18 @@ export class EditorController implements SlotHost {
|
||||
});
|
||||
}
|
||||
|
||||
closeTab(paneId: string, tabId: string): Promise<boolean> {
|
||||
return this.removeGuarded((s) => (s.panes[paneId] ? closeTab(s, paneId, tabId) : s));
|
||||
async closeTab(paneId: string, tabId: string): Promise<boolean> {
|
||||
const hadFocus = this.slots.get(tabId)?.view?.hasFocus ?? false;
|
||||
const closed = await this.removeGuarded((s) => (s.panes[paneId] ? closeTab(s, paneId, tabId) : s));
|
||||
// The closed editor had the keyboard: hand it to the tab that took its place.
|
||||
if (closed && hadFocus) await this.focusActiveEditor();
|
||||
return closed;
|
||||
}
|
||||
|
||||
private async focusActiveEditor() {
|
||||
const tab = this.activeTabOf();
|
||||
if (tab) await this.ensureSlot(tab.id);
|
||||
if (this.activeTabOf()?.id === tab?.id) this.focus();
|
||||
}
|
||||
closeOthers(paneId: string, tabId: string): Promise<boolean> {
|
||||
return this.removeGuarded((s) => (s.panes[paneId] ? closeOthers(s, paneId, tabId) : s), {
|
||||
|
||||
Reference in new issue
Заблокувати користувача