Skip to content

armgit / Orkas

Public Imported from GitHub
0

Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.

Keep keyboard focus stable during home refreshes

wytf8c2eec187af
diff --git a/src/renderer/modules/home.js b/src/renderer/modules/home.js
index 289d386b..dbce54b5 100644
--- a/src/renderer/modules/home.js
+++ b/src/renderer/modules/home.js
@@ -367,7 +367,22 @@ function _homeRender() {
// Groups keep this order; one without items is left out entirely.
const sections = ['todos', 'automations', 'tasks'].filter((section) => counts[section] > 0);
const host = document.getElementById('home-groups');
- if (host) host.innerHTML = sections.map(_homeSectionHtml).join('');
+ if (host) {
+ // Background refreshes can arrive between focusing a control and pressing
+ // Enter. Preserve its identity across replacement without moving the view.
+ const active = document.activeElement;
+ const focusKey = active && host.contains(active)
+ ? ['homeToggle', 'homeAction', 'homeTodo', 'homeCid'].find(key => active.dataset[key])
+ : null;
+ const focusValue = focusKey ? active.dataset[focusKey] : '';
+ const focusProject = focusKey ? active.dataset.homePid : undefined;
+ host.innerHTML = sections.map(_homeSectionHtml).join('');
+ if (focusKey) {
+ const replacement = Array.from(host.querySelectorAll('button')).find(button =>
+ button.dataset[focusKey] === focusValue && button.dataset.homePid === focusProject);
+ replacement?.focus({ preventScroll: true });
+ }
+ }
_homeApplyState(sections.length ? 'populated' : 'empty');
}
diff --git a/test/renderer/home.test.ts b/test/renderer/home.test.ts
index 1eeff586..aba5a522 100644
--- a/test/renderer/home.test.ts
+++ b/test/renderer/home.test.ts
@@ -450,6 +450,46 @@ describe('Commander home states', () => {
});
});
+describe('Commander home keyboard continuity during refresh', () => {
+ it.each(['homeToggle', 'homeAction', 'homeTodo', 'homeCid'])('keeps the focused %s control usable when new work arrives', async (key) => {
+ const h = loadHome();
+ const document = h.context.document;
+ const oldButton = element({ dataset: { [key]: 'selected', homePid: 'p1' } });
+ const replacement = element({ dataset: { [key]: 'selected', homePid: 'p1' },
+ focus: vi.fn(() => { document.activeElement = replacement; }) });
+ const unrelated = element({ dataset: { [key]: 'other', homePid: 'p1' } });
+ const otherProject = element({ dataset: { [key]: 'selected', homePid: 'p2' } });
+ const host = h.els['home-groups'];
+ host.contains = (node: unknown) => node === oldButton;
+ host.querySelectorAll = () => [unrelated, otherProject, replacement];
+ document.activeElement = oldButton;
+ Object.defineProperty(host, 'innerHTML', { set() { document.activeElement = null; } });
+
+ h.context.homeRefresh();
+ h.timers.find((timer) => timer.ms === 500)!.fn();
+ await h.settle();
+
+ expect(document.activeElement).toBe(replacement);
+ expect(replacement.focus).toHaveBeenCalledWith({ preventScroll: true });
+ expect(unrelated.focusCount).toBe(0);
+ expect(otherProject.focusCount).toBe(0);
+ });
+
+ it.each(['outside', 'removed'])('does not move focus to another control when the focused control is %s', async (location) => {
+ const h = loadHome();
+ const original = element({ dataset: { homeToggle: 'todos' } });
+ const other = element({ dataset: { homeToggle: 'tasks' } });
+ h.context.document.activeElement = original;
+ h.els['home-groups'].contains = () => location !== 'outside';
+ h.els['home-groups'].querySelectorAll = () => [other];
+ h.context.homeRefresh();
+ h.timers.find((timer) => timer.ms === 500)!.fn();
+ await h.settle();
+ expect(other.focusCount).toBe(0);
+ expect(original.focusCount).toBe(0);
+ });
+});
+
describe('Commander home Connectors link', () => {
it('opens Connectors directly without a chooser or starting setup', async () => {
const h = loadHome();