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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
Properly focus (and unfocus) multi-cell delete confirmation (#5690)
Trevor Manza79276fc4a00
diff --git a/frontend/src/components/editor/navigation/multi-cell-action-toolbar.tsx b/frontend/src/components/editor/navigation/multi-cell-action-toolbar.tsxindex 04c64bb5ef..2a25eb8497 100644--- a/frontend/src/components/editor/navigation/multi-cell-action-toolbar.tsx+++ b/frontend/src/components/editor/navigation/multi-cell-action-toolbar.tsx@@ -19,6 +19,7 @@ import {ZapOffIcon,} from "lucide-react";import React from "react";+import { FocusScope } from "react-aria";import useEvent from "react-use-event-hook";import { MinimalShortcut } from "@/components/shortcuts/renderShortcut";import { Button } from "@/components/ui/button";@@ -357,6 +358,7 @@ const MultiCellPendingDeleteBar: React.FC<{ cellIds: CellId[] }> = ({}) => {const pendingDeleteService = usePendingDeleteService();const deleteCell = useDeleteManyCellsCallback();+ const selectionActions = useCellSelectionActions();if (!pendingDeleteService.shouldConfirmDelete) {return null;@@ -380,27 +382,36 @@ const MultiCellPendingDeleteBar: React.FC<{ cellIds: CellId[] }> = ({Are you sure you want to delete?</p></div>- <div className="flex items-center gap-2 mt-3">- <Button- size="xs"- variant="ghost"- onClick={() => pendingDeleteService.clear()}- className="text-[var(--amber-11)] hover:bg-[var(--amber-4)] hover:text-[var(--amber-11)]"- >- Cancel- </Button>- <Button- size="xs"- variant="secondary"- onClick={() => {- deleteCell({ cellIds });- pendingDeleteService.clear();+ <FocusScope restoreFocus={true} autoFocus={true}>+ <div+ className="flex items-center gap-2 mt-3"+ onKeyDown={(e) => {+ // Stop propagation to prevent Cell's resumeCompletionHandler+ e.stopPropagation();}}- className="bg-[var(--amber-11)] hover:bg-[var(--amber-12)] text-white border-[var(--amber-11)]">- Delete- </Button>- </div>+ <Button+ size="xs"+ variant="ghost"+ onClick={() => pendingDeleteService.clear()}+ className="text-[var(--amber-11)] hover:bg-[var(--amber-4)] hover:text-[var(--amber-11)]"+ >+ Cancel+ </Button>+ <Button+ size="xs"+ variant="secondary"+ onClick={() => {+ deleteCell({ cellIds });+ pendingDeleteService.clear();+ selectionActions.clear();+ }}+ className="bg-[var(--amber-11)] hover:bg-[var(--amber-12)] text-white border-[var(--amber-11)]"+ >+ Delete+ </Button>+ </div>+ </FocusScope></div></div></div>diff --git a/frontend/src/components/editor/navigation/navigation.ts b/frontend/src/components/editor/navigation/navigation.tsindex fde97f72b9..f3396ced31 100644--- a/frontend/src/components/editor/navigation/navigation.ts+++ b/frontend/src/components/editor/navigation/navigation.ts@@ -81,7 +81,6 @@ function useCellFocusProps(cellId: CellId) {const focusActions = useCellFocusActions();const actions = useCellActions();const setTemporarilyShownCode = useSetAtom(temporarilyShownCodeAtom);- const pendingDeleteService = usePendingDeleteService();// This occurs at the cell level and descedants.const { focusWithinProps } = useFocusWithin({@@ -93,7 +92,6 @@ function useCellFocusProps(cellId: CellId) {// On blur, hide the code if it was temporarily shown.setTemporarilyShownCode(false);actions.markTouched({ cellId });- pendingDeleteService.clear();focusActions.blurCell();},});