Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

Fix component Escape focus (#6754)

Dimitri POSTOLOV5ab21772938f
diff --git a/.changeset/component-escape-returns-focus.md b/.changeset/component-escape-returns-focus.md
new file mode 100644
index 000000000..eb00bbb2e
--- /dev/null
+++ b/.changeset/component-escape-returns-focus.md
@@ -0,0 +1,5 @@
+---
+"@inkeep/open-knowledge": patch
+---
+
+Pressing Escape in the Properties panel of a component that holds content, such as a Callout you just inserted, now returns focus to the document with the component still selected, so undo and typing work right away.
diff --git a/knip.config.ts b/knip.config.ts
index 03ef8d4a4..36a395261 100644
--- a/knip.config.ts
+++ b/knip.config.ts
@@ -155,15 +155,11 @@ export default {
'src/shadow-fixture-launch.test-helper.mjs',
],
project: 'src/**',
- ignoreDependencies: [
- '@types/shell-quote',
- ],
+ ignoreDependencies: ['@types/shell-quote'],
},
'packages/cli': {
entry: ['src/**/*.test.ts', 'scripts/*.ts', 'tests/**/*.ts', 'src/parse-worker.ts'],
- ignoreDependencies: [
- 'yjs',
- ],
+ ignoreDependencies: ['yjs'],
},
'packages/desktop': {
entry: [
diff --git a/packages/app/src/editor/extensions/JsxComponentView.tsx b/packages/app/src/editor/extensions/JsxComponentView.tsx
index 223524434..1c2344f7f 100644
--- a/packages/app/src/editor/extensions/JsxComponentView.tsx
+++ b/packages/app/src/editor/extensions/JsxComponentView.tsx
@@ -140,6 +140,7 @@ export function JsxComponentView({ node, editor, extension, getPos, selected }:
const descriptor = getDescriptor(node.attrs.componentName as string);
const [renderError, setRenderError] = useState<Error | null>(null);
const [popoverOpen, setPopoverOpen] = useState(false);
+ const panelInteractedOutside = useRef(false);
const wasSelected = useRef(false);
const pos = typeof getPos === 'function' ? getPos() : undefined;
@@ -1038,14 +1039,17 @@ export function JsxComponentView({ node, editor, extension, getPos, selected }:
align={showPlaceholder ? 'center' : 'start'}
sideOffset={showPlaceholder ? -4 : 8}
className="w-64 p-3 z-60 overflow-y-auto subtle-scrollbar max-h-(--radix-popper-available-height) overscroll-contain"
- onCloseAutoFocus={
- isSelfClosingLeaf
- ? (e) => {
- e.preventDefault();
- editor.view.focus();
- }
- : undefined
- }
+ onInteractOutside={() => {
+ panelInteractedOutside.current = true;
+ }}
+ onCloseAutoFocus={(e) => {
+ const interactedOutside = panelInteractedOutside.current;
+ panelInteractedOutside.current = false;
+ if (!isSelfClosingLeaf && interactedOutside) return;
+ e.preventDefault();
+ const view = getEditorView(editor);
+ if (view && !view.isDestroyed) view.focus();
+ }}
>
<div className="text-xs font-medium text-muted-foreground mb-2">
<Trans>{propPanelDescriptorLabel} Properties</Trans>
diff --git a/packages/app/tests/integration/bug3-source-mode-writeback.test.ts b/packages/app/tests/integration/bug3-source-mode-writeback.test.ts
index 4549c74b3..a50b00123 100644
--- a/packages/app/tests/integration/bug3-source-mode-writeback.test.ts
+++ b/packages/app/tests/integration/bug3-source-mode-writeback.test.ts
@@ -1,4 +1,3 @@
-
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { setTimeout as wait } from 'node:timers/promises';
diff --git a/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts b/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts
index 4fc2c11f9..6fcdc23f2 100644
--- a/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts
+++ b/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts
@@ -1,4 +1,3 @@
-
import { setTimeout as wait } from 'node:timers/promises';
import { normalizeBridge } from '@inkeep/open-knowledge-core';
import { updateYFragment } from '@tiptap/y-tiptap';
diff --git a/packages/app/tests/integration/interior-edit-freshness.test.ts b/packages/app/tests/integration/interior-edit-freshness.test.ts
index 9f2f6feb6..40b5cdfd6 100644
--- a/packages/app/tests/integration/interior-edit-freshness.test.ts
+++ b/packages/app/tests/integration/interior-edit-freshness.test.ts
@@ -1,4 +1,3 @@
-
import { setTimeout as wait } from 'node:timers/promises';
import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';
import { afterAll, beforeAll, describe, expect, test } from 'vitest';
diff --git a/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts b/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts
index 2a085742b..93666af70 100644
--- a/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts
+++ b/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts
@@ -1,4 +1,3 @@
-
import { setTimeout as wait } from 'node:timers/promises';
import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';
import { afterAll, beforeAll, describe, expect, test } from 'vitest';
diff --git a/packages/app/tests/integration/producer-guard-wiring.test.ts b/packages/app/tests/integration/producer-guard-wiring.test.ts
index 878d5196b..867598d34 100644
--- a/packages/app/tests/integration/producer-guard-wiring.test.ts
+++ b/packages/app/tests/integration/producer-guard-wiring.test.ts
@@ -1,4 +1,3 @@
-
import { setTimeout as wait } from 'node:timers/promises';
import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';
import { afterAll, beforeAll, describe, expect, test } from 'vitest';
diff --git a/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.ts b/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.ts
index 4ada3cf26..0970ac12f 100644
--- a/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.ts
+++ b/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.ts
@@ -1,4 +1,3 @@
-
import { randomUUID } from 'node:crypto';
import { afterEach, describe, expect, test } from 'vitest';
import { agentWriteMd, createTestServer, type TestServer } from './test-harness';
diff --git a/packages/app/tests/integration/qa-045-restore-after-gc.test.ts b/packages/app/tests/integration/qa-045-restore-after-gc.test.ts
index cbe2b705f..b632185e1 100644
--- a/packages/app/tests/integration/qa-045-restore-after-gc.test.ts
+++ b/packages/app/tests/integration/qa-045-restore-after-gc.test.ts
@@ -1,4 +1,3 @@
-
import { execFileSync } from 'node:child_process';
import { randomUUID } from 'node:crypto';
import { join } from 'node:path';
diff --git a/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.ts b/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.ts
index 89bc9b4d9..c530ce4ba 100644
--- a/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.ts
+++ b/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.ts
@@ -1,4 +1,3 @@
-
import { randomUUID } from 'node:crypto';
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest';
import type * as Y from 'yjs';
diff --git a/packages/app/tests/integration/undo-after-rollback.test.ts b/packages/app/tests/integration/undo-after-rollback.test.ts
index a78aeb0e4..d3767adc9 100644
--- a/packages/app/tests/integration/undo-after-rollback.test.ts
+++ b/packages/app/tests/integration/undo-after-rollback.test.ts
@@ -1,4 +1,3 @@
-
import { ROLLBACK_ORIGIN } from '@inkeep/open-knowledge-server';
import { afterAll, beforeAll, describe, expect, test } from 'vitest';
import * as Y from 'yjs';
diff --git a/packages/app/tests/integration/undo-recycle-reset.test.ts b/packages/app/tests/integration/undo-recycle-reset.test.ts
index e7cc69c3f..b076f955c 100644
--- a/packages/app/tests/integration/undo-recycle-reset.test.ts
+++ b/packages/app/tests/integration/undo-recycle-reset.test.ts
@@ -1,4 +1,3 @@
-
import { writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { setTimeout as wait } from 'node:timers/promises';
diff --git a/packages/app/tests/integration/undo-rederive-survival.test.ts b/packages/app/tests/integration/undo-rederive-survival.test.ts
index 9ddcd0730..7935e35f8 100644
--- a/packages/app/tests/integration/undo-rederive-survival.test.ts
+++ b/packages/app/tests/integration/undo-rederive-survival.test.ts
@@ -1,4 +1,3 @@
-
import { prependFrontmatter } from '@inkeep/open-knowledge-core';
import { Plugin, PluginKey } from '@tiptap/pm/state';
import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';
diff --git a/packages/app/tests/stress/slash-command-auto-open.e2e.ts b/packages/app/tests/stress/slash-command-auto-open.e2e.ts
index e2056a5e1..521efaebd 100644
--- a/packages/app/tests/stress/slash-command-auto-open.e2e.ts
+++ b/packages/app/tests/stress/slash-command-auto-open.e2e.ts
@@ -1,6 +1,7 @@
import {
expect,
focusEditor,
+ settleFrames,
test,
waitForActiveProviderSynced,
waitForSlashMenuFirstOption,
@@ -444,3 +445,65 @@ test('PLACEHOLDER-CLOSE-RETURNS-DOM-FOCUS: typing after Escape lands keystrokes
)
.toEqual({ focusInEditor: true, sentinelInDoc: true, imgFound: true });
});
+
+test('CONTAINER-CLOSE-RETURNS-DOM-FOCUS: Escape after inserting a Callout leaves it selected in the focused editor', async ({
+ page,
+ api,
+}) => {
+ const docName = `container-close-focus-${Math.random().toString(36).slice(2, 10)}`;
+ await api.createPage(`${docName}.md`);
+ await page.goto(`/#/${docName}`);
+ await page.waitForSelector('.ProseMirror:not(.composer-prosemirror)');
+ await waitForActiveProviderSynced(page);
+ await page.click('.ProseMirror:not(.composer-prosemirror)');
+
+ await page.keyboard.type('/callout');
+ await waitForSlashMenuFirstOption(page, 'callout');
+ await page.keyboard.press('Enter');
+
+ await expect(page.locator('[data-prop-panel]')).toBeVisible();
+
+ await page.keyboard.press('Escape');
+ await expect(page.locator('[data-prop-panel]')).toBeHidden();
+
+ await expect
+ .poll(
+ () =>
+ page.evaluate(() => {
+ const ed = window.__activeEditor;
+ if (!ed) return null;
+ const selection = ed.state.selection as {
+ node?: { attrs: { componentName?: string } };
+ };
+ return {
+ editorFocused: document.activeElement === ed.view.dom,
+ selectedComponent: selection.node?.attrs.componentName ?? null,
+ };
+ }),
+ { message: 'Escape left focus outside the editor, or the new Callout lost its selection' },
+ )
+ .toEqual({ editorFocused: true, selectedComponent: 'Callout' });
+
+ await page.keyboard.press('ControlOrMeta+z');
+ await expect
+ .poll(
+ () =>
+ page.evaluate(() => {
+ let callouts = 0;
+ window.__activeEditor?.state.doc.descendants((n) => {
+ if (n.type.name === 'jsxComponent' && n.attrs.componentName === 'Callout') callouts++;
+ return true;
+ });
+ return callouts;
+ }),
+ { message: 'Cmd+Z after Escape did not undo the Callout insert' },
+ )
+ .toBe(0);
+ await settleFrames(page);
+
+ const SENTINEL = 'after-undo-canary';
+ await page.keyboard.type(SENTINEL);
+ await expect
+ .poll(() => page.evaluate(() => window.__activeEditor?.state.doc.textContent ?? ''))
+ .toContain(SENTINEL);
+});
diff --git a/packages/core/src/bridge/compose.ts b/packages/core/src/bridge/compose.ts
index 2a597ec3d..f4cc8a286 100644
--- a/packages/core/src/bridge/compose.ts
+++ b/packages/core/src/bridge/compose.ts
@@ -1,4 +1,3 @@
-
import { prependFrontmatter, stripFrontmatter } from '../extensions/frontmatter.ts';
export type ComposeAdjustment = 'none' | 'body' | 'frontmatter' | 'unresolved';
diff --git a/packages/core/src/bridge/doc-boundary-space.ts b/packages/core/src/bridge/doc-boundary-space.ts
index ffd8fce06..e7e63f43d 100644
--- a/packages/core/src/bridge/doc-boundary-space.ts
+++ b/packages/core/src/bridge/doc-boundary-space.ts
@@ -1,4 +1,3 @@
-
import { FRONTMATTER_RE, stripFrontmatter } from '../extensions/frontmatter.ts';
import { carriedEdgeEmpties, type DocEdgeEmpties } from '../markdown/doc-edge-blank-runs.ts';
diff --git a/packages/core/src/markdown/comment-promoter.ts b/packages/core/src/markdown/comment-promoter.ts
index fb0ba5a7c..fc267cbea 100644
--- a/packages/core/src/markdown/comment-promoter.ts
+++ b/packages/core/src/markdown/comment-promoter.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Paragraph, PhrasingContent, Root, RootContent, Text } from 'mdast';
import { SKIP, visit } from 'unist-util-visit';
import type { VFile } from 'vfile';
diff --git a/packages/core/src/markdown/merged-walker.ts b/packages/core/src/markdown/merged-walker.ts
index ae8cb390b..861003fb4 100644
--- a/packages/core/src/markdown/merged-walker.ts
+++ b/packages/core/src/markdown/merged-walker.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Parent, Root } from 'mdast';
import { SKIP, visit } from 'unist-util-visit';
import type { VFile } from 'vfile';
diff --git a/packages/core/src/markdown/safe-url.ts b/packages/core/src/markdown/safe-url.ts
index 8be632ba4..4d3250d3a 100644
--- a/packages/core/src/markdown/safe-url.ts
+++ b/packages/core/src/markdown/safe-url.ts
@@ -1,4 +1,3 @@
-
export const SAFE_URL_SCHEMES = ['https', 'http', 'mailto', 'tel', 'ftp', 'sms'] as const;
const SCHEME_ALT = SAFE_URL_SCHEMES.map((s) => `${s}:`).join('|');