Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(ok): let a second Skills tab take focus when clicked (PRD-7834) (#3333)

tim-inkeep84feab2bd5dc
diff --git a/.changeset/skills-new-tab-activation.md b/.changeset/skills-new-tab-activation.md
new file mode 100644
index 000000000..ef8ed184b
--- /dev/null
+++ b/.changeset/skills-new-tab-activation.md
@@ -0,0 +1,5 @@
+---
+"@inkeep/open-knowledge": patch
+---
+
+Clicking a second empty tab in the Skills editor now switches to it. Every empty Skills tab shares one route (the Skills home), so re-resolving that route while you already had one open snapped you back to the leftmost empty tab. Activation looked frozen: clicking another empty tab did nothing, the + button appeared to open a tab it never took you to, and Cmd-2 wouldn't move either. Empty Files tabs were unaffected. The Skills home now keeps whichever of its tabs is already active instead of always picking the first.
diff --git a/packages/app/src/editor/DocumentContext.dom.test.tsx b/packages/app/src/editor/DocumentContext.dom.test.tsx
index 1dc5941db..aade6ee68 100644
--- a/packages/app/src/editor/DocumentContext.dom.test.tsx
+++ b/packages/app/src/editor/DocumentContext.dom.test.tsx
@@ -383,6 +383,18 @@ function CloseActiveHarness() {
<button type="button" onClick={() => ctx.reopenClosedTab()}>
Reopen closed
</button>
+ <button type="button" onClick={() => ctx.openTarget({ kind: 'skills', target: 'skills' })}>
+ Resolve skills hub
+ </button>
+ <button
+ type="button"
+ onClick={() => {
+ const first = ctx.newTabIds[0];
+ if (first) ctx.activateNewTabInPane(ctx.focusedPaneId, first);
+ }}
+ >
+ Activate first new tab
+ </button>
</>
);
}
@@ -1662,3 +1674,37 @@ describe('DocumentContext local rename reconciliation — preserves tab position
});
});
});
+
+describe('DocumentContext skills-surface new tabs', () => {
+ afterEach(() => {
+ window.localStorage.clear();
+ cleanup();
+ });
+
+ test('re-resolving the skills hub keeps the active new tab', async () => {
+ render(<CloseActiveHarness />, { wrapper: ProviderHarness });
+ const user = userEvent.setup();
+ const newTabIds = () => (screen.getByTestId('new-tabs').textContent ?? '').split('|');
+ const activeNewTabId = () => screen.getByTestId('active-new-tab').textContent;
+
+ await user.click(screen.getByRole('button', { name: 'Show skills' }));
+ await user.click(screen.getByRole('button', { name: 'Open new' }));
+
+ const [first, second] = newTabIds();
+ expect(first).toMatch(/^new-tab:skills:\d+$/);
+ expect(second).toMatch(/^new-tab:skills:\d+$/);
+ expect(activeNewTabId()).toBe(second);
+
+ // The skills hub hash is the same for every skills new tab, so the nav
+ // effect re-resolves it on unrelated re-renders. That must not move the
+ // user off the tab they are on.
+ await user.click(screen.getByRole('button', { name: 'Resolve skills hub' }));
+ expect(activeNewTabId()).toBe(second);
+
+ await user.click(screen.getByRole('button', { name: 'Activate first new tab' }));
+ expect(activeNewTabId()).toBe(first);
+
+ await user.click(screen.getByRole('button', { name: 'Resolve skills hub' }));
+ expect(activeNewTabId()).toBe(first);
+ });
+});
diff --git a/packages/app/src/editor/DocumentContext.tsx b/packages/app/src/editor/DocumentContext.tsx
index 67a04bd4e..8d8fb3b69 100644
--- a/packages/app/src/editor/DocumentContext.tsx
+++ b/packages/app/src/editor/DocumentContext.tsx
@@ -1611,7 +1611,17 @@ export function DocumentProvider({ children }: { children: ReactNode }) {
function activateOrOpenSurfaceNewTab(paneId: EditorPaneId, skills: boolean) {
const pane = workspaceRef.current.panes.find((candidate) => candidate.id === paneId);
if (!pane) return;
- const existingTabId = pane.newTabIds.find((tabId) => isSkillsNewTabId(tabId) === skills);
+ // A pane can hold several new tabs per surface, and a surface hub route
+ // (`#/__skills__`) addresses the surface, not one tab - so re-resolving it
+ // has to keep whichever tab is already active instead of snapping back to
+ // the first. Without this the nav effect, which re-fires on the unchanged
+ // hub hash, steals activation from every other new tab on that surface.
+ const activeOnSurface =
+ pane.activeNewTabId !== null && isSkillsNewTabId(pane.activeNewTabId) === skills
+ ? pane.activeNewTabId
+ : null;
+ const existingTabId =
+ activeOnSurface ?? pane.newTabIds.find((tabId) => isSkillsNewTabId(tabId) === skills);
setSkillsSidebarState(null);
if (existingTabId) {
updatePaneState(