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 `Ctrl+Click` to select cell type on Windows/Linux (#7580)

Trevor Manz45e64f2daf60
diff --git a/frontend/src/components/editor/cell/CreateCellButton.tsx b/frontend/src/components/editor/cell/CreateCellButton.tsx
index baacbd929a..d98d69aa53 100644
--- a/frontend/src/components/editor/cell/CreateCellButton.tsx
+++ b/frontend/src/components/editor/cell/CreateCellButton.tsx
@@ -18,7 +18,6 @@ import {
} from "@/core/websocket/connection-utils";
import type { WebSocketState } from "@/core/websocket/types";
import { cn } from "@/utils/cn";
-import { Events } from "@/utils/events";
import { Tooltip } from "../../ui/tooltip";
import { MarkdownIcon, PythonIcon } from "./code/icons";
@@ -35,6 +34,7 @@ export const CreateCellButton = ({
}) => {
const { createNewCell, addSetupCellIfDoesntExist } = useCellActions();
const shortcut = `${oneClickShortcut}-Click`;
+ const [open, setOpen] = useState(false);
const [justOpened, setJustOpened] = useState(false);
const baseTooltipContent =
@@ -80,23 +80,49 @@ export const CreateCellButton = ({
return <div className="mr-3 text-muted-foreground">{icon}</div>;
};
- const handleButtonClick = (e: React.MouseEvent) => {
+ const openDropdown = () => {
+ setOpen(true);
+ setJustOpened(true);
+ // Allow interactions after a brief delay to prevent the dropdown items immediately being clicked
+ setTimeout(() => setJustOpened(false), 200);
+ };
+
+ // We use onPointerDownCapture (not onPointerDown) to intercept events in
+ // capture phase before Radix's DropdownMenuTrigger sees them. Radix ignores
+ // Ctrl+Click (likely to avoid interfering with browser), so we bypass its
+ // trigger entirely and manage the dropdown's open state ourselves.
+ const handlePointerDownCapture = (e: React.MouseEvent) => {
+ // Ignore right-clicks, handled by onContextMenuCapture
+ if (e.button === 2) {
+ return;
+ }
+
+ // Don't propagate event to Radix
+ e.preventDefault();
+ e.stopPropagation();
+
const hasModifier =
oneClickShortcut === "shift" ? e.shiftKey : e.metaKey || e.ctrlKey;
- if (!hasModifier) {
- e.preventDefault();
- e.stopPropagation();
+
+ if (hasModifier) {
+ openDropdown();
+ } else {
addPythonCell();
}
};
- const handleOpenChange = (open: boolean) => {
- if (open) {
+ const handleContextMenu = (e: React.MouseEvent) => {
+ e.preventDefault();
+ e.stopPropagation();
+ openDropdown();
+ };
+
+ const handleOpenChange = (isOpen: boolean) => {
+ setOpen(isOpen);
+ if (isOpen) {
setJustOpened(true);
// Allow interactions after a brief delay
- setTimeout(() => {
- setJustOpened(false);
- }, 200);
+ setTimeout(() => setJustOpened(false), 200);
}
};
@@ -111,14 +137,15 @@ export const CreateCellButton = ({
};
return (
- <DropdownMenu onOpenChange={handleOpenChange}>
- <DropdownMenuTrigger asChild={true} onPointerDown={handleButtonClick}>
+ <DropdownMenu open={open} onOpenChange={handleOpenChange}>
+ <DropdownMenuTrigger asChild={true}>
<Button
className={cn(
"border-none hover-action shadow-none! bg-transparent! focus-visible:outline-none",
isAppInteractionDisabled(connectionState) && " inactive-button",
)}
- onMouseDown={Events.preventFocus}
+ onPointerDownCapture={handlePointerDownCapture}
+ onContextMenuCapture={handleContextMenu}
size="small"
data-testid="create-cell-button"
>