diff --git a/docs/guides/editor_features/overview.md b/docs/guides/editor_features/overview.md index c4a5b0686f6..59aa0a195ec 100644 --- a/docs/guides/editor_features/overview.md +++ b/docs/guides/editor_features/overview.md @@ -53,6 +53,7 @@ editing their contents. - `Shift+↓`/`Shift+↑` - multi-select cells - `Enter` - edit selected cell - `a`/`b` - new cell above/below +- `q` - new SQL cell below - `c`/`v` - copy/paste cells - `s` - save notebook - `Shift+Enter` - run cell and move to next diff --git a/frontend/src/components/editor/navigation/navigation.ts b/frontend/src/components/editor/navigation/navigation.ts index cb3a2065a19..1bb0716d363 100644 --- a/frontend/src/components/editor/navigation/navigation.ts +++ b/frontend/src/components/editor/navigation/navigation.ts @@ -12,6 +12,7 @@ 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 { maybeAddMarimoImport } from "@/core/cells/add-missing-import"; import { cellIdsAtom, notebookAtom, useCellActions } from "@/core/cells/cells"; import { useCellFocusActions } from "@/core/cells/focus"; import type { CellId } from "@/core/cells/ids"; @@ -26,6 +27,7 @@ import { closeSignatureHint, signatureHintField, } from "@/core/codemirror/completion/signature-hint"; +import { LanguageAdapters } from "@/core/codemirror/language/LanguageAdapters"; import { hotkeysAtom, isAiFeatureEnabled, @@ -551,6 +553,23 @@ export function useCellNavigationProps( actions.createNewCell({ cellId, before: false, autoFocus: true }); return true; }, + "command.createSqlCellAfter": (cellId) => { + if (Events.hasModifier(evt)) { + return false; + } + const importCellId = maybeAddMarimoImport({ + autoInstantiate: true, + createNewCell: actions.createNewCell, + fromCellId: cellId, + }); + actions.createNewCell({ + cellId: importCellId ?? cellId, + before: false, + autoFocus: true, + code: LanguageAdapters.sql.defaultCode, + }); + return true; + }, "cell.delete": () => { // Only handle if destructive_delete is enabled if (!userConfig.keymap.destructive_delete) { diff --git a/frontend/src/core/hotkeys/hotkeys.ts b/frontend/src/core/hotkeys/hotkeys.ts index 77b0168ad15..25002b7995b 100644 --- a/frontend/src/core/hotkeys/hotkeys.ts +++ b/frontend/src/core/hotkeys/hotkeys.ts @@ -458,6 +458,11 @@ const DEFAULT_HOT_KEY = { group: "Command", key: "b", }, + "command.createSqlCellAfter": { + name: "Create a SQL cell after current cell", + group: "Command", + key: "q", + }, "command.copyCell": { name: "Copy cell", group: "Command",