Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(notebooks): keep cmd+a inside embedded code cell editors (#77276)

Sinan Kucukkoseler2b4acf09b74c
diff --git a/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.test.ts b/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.test.ts
index b7a051885bc4..421ceb977b73 100644
--- a/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.test.ts
+++ b/frontend/src/lib/components/MarkdownNotebook/MarkdownNotebook.test.ts
@@ -5248,6 +5248,44 @@ Tail paragraph`),
expect(window.getSelection()?.toString()).not.toContain('Tail paragraph')
})
+ it('leaves Cmd+A alone inside a component code editor', () => {
+ const registry = createMarkdownNotebookRegistry([
+ {
+ tagName: 'Embed',
+ label: 'Embed',
+ category: 'Media',
+ // Stands in for the Monaco editor of an SQLV2 or PythonV2 cell. With EditContext on,
+ // Monaco takes focus on a plain div rather than a hidden textarea, so the notebook can
+ // only tell it apart by the `monaco-editor` container.
+ ViewComponent: () =>
+ createElement(
+ 'div',
+ { className: 'monaco-editor' },
+ createElement('div', { className: 'native-edit-context', tabIndex: 0 })
+ ),
+ },
+ ])
+ const { container } = render(
+ createElement(MarkdownNotebook, {
+ value: withNotebookTitle(`Before component
+
+<Embed />
+
+After component`),
+ registry,
+ })
+ )
+ const component = container.querySelector('.MarkdownNotebook__component-shell') as HTMLElement
+ const editorInputHost = container.querySelector('.native-edit-context') as HTMLElement
+ window.getSelection()?.removeAllRanges()
+
+ editorInputHost.focus()
+ fireSelectAllShortcut(editorInputHost)
+
+ expect(window.getSelection()?.toString()).toEqual('')
+ expect(component.classList.contains('MarkdownNotebook__component-shell--selected')).toBe(false)
+ })
+
it('selects text and components with Cmd+A from a focused component', () => {
const onChange = jest.fn()
const registry = createMarkdownNotebookRegistry([
diff --git a/frontend/src/lib/components/MarkdownNotebook/domSelection.ts b/frontend/src/lib/components/MarkdownNotebook/domSelection.ts
index 8405ffc99121..53e244767569 100644
--- a/frontend/src/lib/components/MarkdownNotebook/domSelection.ts
+++ b/frontend/src/lib/components/MarkdownNotebook/domSelection.ts
@@ -648,8 +648,16 @@ export function rangeIntersectsNode(range: Range, node: Node): boolean {
}
}
+// Monaco belongs in this list because an embedded editor (SQLV2 and PythonV2 cells, the debug drawer)
+// owns its own editing and key handling, so the notebook has to leave Cmd+A, Backspace, copy and paste
+// to it rather than acting on the whole document. Tag names alone don't find it: with EditContext
+// enabled, which is Monaco's default on Chromium, the focused input host is a plain
+// `div.native-edit-context` instead of the legacy hidden textarea, and the DOM selection stays wherever
+// it was before the editor took focus.
+const NATIVE_EDITABLE_SELECTOR = 'input, textarea, select, .monaco-editor'
+
export function isNativeEditableElement(element: HTMLElement): boolean {
- return Boolean(element.closest('input, textarea, select'))
+ return Boolean(element.closest(NATIVE_EDITABLE_SELECTOR))
}
export function isFormattingToolbarFocused(): boolean {