Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: dont hide cell if interactive with vim search or dropdowns (#7911)

Myles Scolnick43fee21d8f48
diff --git a/frontend/src/components/data-table/cell-utils.ts b/frontend/src/components/data-table/cell-utils.ts
index a83828e568..2e41a4529d 100644
--- a/frontend/src/components/data-table/cell-utils.ts
+++ b/frontend/src/components/data-table/cell-utils.ts
@@ -1,5 +1,7 @@
/* Copyright 2026 Marimo. All rights reserved. */
+import type { CellId } from "@/core/cells/ids";
+
export const DATA_CELL_ID = "data-cell-id";
export function getCellDomProps(cellId: string) {
@@ -7,3 +9,11 @@ export function getCellDomProps(cellId: string) {
[DATA_CELL_ID]: cellId,
};
}
+
+export const DATA_FOR_CELL_ID = "data-for-cell-id";
+
+export function getCellForDomProps(cellId: CellId) {
+ return {
+ [DATA_FOR_CELL_ID]: cellId,
+ };
+}
diff --git a/frontend/src/components/editor/cell/cell-actions.tsx b/frontend/src/components/editor/cell/cell-actions.tsx
index d37ccfdc64..0757a2e7b4 100644
--- a/frontend/src/components/editor/cell/cell-actions.tsx
+++ b/frontend/src/components/editor/cell/cell-actions.tsx
@@ -12,6 +12,7 @@ import React, {
useState,
} from "react";
import useEvent from "react-use-event-hook";
+import { getCellForDomProps } from "@/components/data-table/cell-utils";
import {
renderMinimalShortcut,
renderShortcut,
@@ -104,7 +105,11 @@ const CellActionsDropdownInternal = (
{...restoreFocus}
>
<Command>
- <CommandInput placeholder="Search actions..." className="h-6 m-1" />
+ <CommandInput
+ placeholder="Search actions..."
+ className="h-6 m-1"
+ {...getCellForDomProps(props.cellId)}
+ />
<CommandList>
<CommandEmpty>No results</CommandEmpty>
{actions.map((group, i) => (
diff --git a/frontend/src/components/editor/navigation/navigation.ts b/frontend/src/components/editor/navigation/navigation.ts
index 93427102ae..d3c39058bd 100644
--- a/frontend/src/components/editor/navigation/navigation.ts
+++ b/frontend/src/components/editor/navigation/navigation.ts
@@ -10,6 +10,7 @@ import {
import { useAtomValue, useSetAtom, useStore } from "jotai";
import { useMemo } from "react";
import { mergeProps, useFocusWithin, useKeyboard } from "react-aria";
+import { DATA_FOR_CELL_ID } from "@/components/data-table/cell-utils";
import { aiCompletionCellAtom } from "@/core/ai/state";
import { cellIdsAtom, notebookAtom, useCellActions } from "@/core/cells/cells";
import { useCellFocusActions } from "@/core/cells/focus";
@@ -101,7 +102,23 @@ function useCellFocusProps(
// On focus, set the last focused cell id.
focusActions.focusCell({ cellId });
},
- onBlurWithin: () => {
+ onBlurWithin: (e) => {
+ // Check if blur is happening because of vim search panel interaction
+ if (isInVimPanel(e.relatedTarget) || isInVimPanel(e.target)) {
+ // Don't hide code if we're just interacting with vim search
+ return;
+ }
+
+ // If the related target is for a cell id (data-for-cell-id), then we don't want to hide the code, otherwise it might
+ // close the dropdown.
+ if (
+ getDataForCellId(e.relatedTarget) === cellId ||
+ getDataForCellId(e.relatedTarget?.closest(`[${DATA_FOR_CELL_ID}]`)) ===
+ cellId
+ ) {
+ return;
+ }
+
// On blur, hide the code if it was temporarily shown.
temporarilyShownCodeActions.remove(cellId);
actions.markTouched({ cellId });
@@ -116,6 +133,27 @@ function useCellFocusProps(
return focusWithinProps;
}
+function isInVimPanel(element: Element | null): boolean {
+ if (!element) {
+ return false;
+ }
+ if (element instanceof HTMLElement) {
+ return element.closest(".cm-vim-panel") !== null;
+ }
+ return false;
+}
+
+function getDataForCellId(element: Element | null | undefined): CellId | null {
+ if (!element) {
+ return null;
+ }
+ const cellId = element.getAttribute(DATA_FOR_CELL_ID);
+ if (!cellId) {
+ return null;
+ }
+ return cellId as CellId;
+}
+
type KeymapHandlers = Record<string, () => boolean>;
/**
diff --git a/frontend/src/core/codemirror/language/panel/panel.tsx b/frontend/src/core/codemirror/language/panel/panel.tsx
index dba4791d41..992d1df9ce 100644
--- a/frontend/src/core/codemirror/language/panel/panel.tsx
+++ b/frontend/src/core/codemirror/language/panel/panel.tsx
@@ -8,6 +8,7 @@ import { Tooltip, TooltipProvider } from "@/components/ui/tooltip";
import { normalizeName } from "@/core/cells/names";
import { type ConnectionName, DUCKDB_ENGINE } from "@/core/datasets/engines";
import { useAutoGrowInputProps } from "@/hooks/useAutoGrowInputProps";
+import { cellIdState } from "../../cells/state";
import { formatSQL } from "../../format";
import { languageAdapterState } from "../extension";
import { MarkdownLanguageAdapter } from "../languages/markdown";
@@ -31,6 +32,7 @@ export const LanguagePanelComponent: React.FC<{
}> = ({ view }) => {
const { spanProps, inputProps } = useAutoGrowInputProps({ minWidth: 50 });
const languageAdapter = view.state.field(languageAdapterState);
+ const cellId = view.state.facet(cellIdState);
let actions: React.ReactNode = <div />;
let showDivider = false;
@@ -93,6 +95,7 @@ export const LanguagePanelComponent: React.FC<{
<SQLEngineSelect
selectedEngine={metadata.engine}
onChange={switchEngine}
+ cellId={cellId}
/>
<div className="flex items-center gap-2 ml-auto">
{metadata.engine === DUCKDB_ENGINE && <SQLModeSelect />}
diff --git a/frontend/src/core/codemirror/language/panel/sql.tsx b/frontend/src/core/codemirror/language/panel/sql.tsx
index db3eca8f99..8fb6654fac 100644
--- a/frontend/src/core/codemirror/language/panel/sql.tsx
+++ b/frontend/src/core/codemirror/language/panel/sql.tsx
@@ -8,6 +8,7 @@ import {
DatabaseBackup,
SearchCheck,
} from "lucide-react";
+import { getCellForDomProps } from "@/components/data-table/cell-utils";
import { transformDisplayName } from "@/components/databases/display";
import { DatabaseLogo } from "@/components/databases/icon";
import { Button } from "@/components/ui/button";
@@ -22,6 +23,7 @@ import {
SelectValue,
} from "@/components/ui/select";
import { Tooltip } from "@/components/ui/tooltip";
+import type { CellId } from "@/core/cells/ids";
import {
dataConnectionsMapAtom,
setLatestEngineSelected,
@@ -38,11 +40,13 @@ import { type SQLMode, useSQLMode } from "../languages/sql/sql-mode";
interface SelectProps {
selectedEngine: ConnectionName;
onChange: (engine: ConnectionName) => void;
+ cellId: CellId;
}
export const SQLEngineSelect: React.FC<SelectProps> = ({
selectedEngine,
onChange,
+ cellId,
}) => {
const connectionsMap = useAtomValue(dataConnectionsMapAtom);
@@ -98,10 +102,10 @@ export const SQLEngineSelect: React.FC<SelectProps> = ({
return (
<div className="flex flex-row gap-1 items-center">
<Select value={selectedEngine} onValueChange={handleSelectEngine}>
- <SQLSelectTrigger>
+ <SQLSelectTrigger {...getCellForDomProps(cellId)}>
<SelectValue placeholder="Select an engine" />
</SQLSelectTrigger>
- <SelectContent>
+ <SelectContent {...getCellForDomProps(cellId)}>
<SelectGroup>
<SelectLabel>Database connections</SelectLabel>
{engineIsDisconnected && (