From d1290c76ea7b7bc980f0591064c04fce67fd9cb3 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Sun, 15 Nov 2026 23:03:35 +0800 Subject: [PATCH] feat(database): data editor row and toolbar commands as actions (#3551) Reload Page, First / Previous / Next / Last Page, Add Row, Export Data, Delete Rows, Restore Rows, Edit Cell and the cell copy commands were menu items or toolbar buttons only. They are now db.* actions supplied by the table editor and the console result grid through their focus handle, so they appear in Find Action and take Keymap shortcuts; menus and buttons run the same actions. DataGrip's defaults bind Reload Page, Previous / Next Page and Add Row, and Delete Rows on Windows and Linux. Closes #3506 --- docs/en/guide/database.mdx | 3 +- docs/zh/guide/database.mdx | 3 +- src/features/database/Grid.tsx | 32 ++++-- src/features/database/ResultsView.tsx | 102 ++++++++++++++++---- src/features/database/TableEditor.tsx | 83 ++++++++++------ src/features/database/cellActions.ts | 38 ++++++++ src/features/database/index.ts | 47 ++++++++- src/features/database/table-editor.test.tsx | 34 ++++++- src/features/database/tableEditorFocus.ts | 31 ++++++ src/platform/keymaps/eclipse-macos.ts | 2 + src/platform/keymaps/eclipse-windows.ts | 3 + src/platform/keymaps/intellij-macos.ts | 11 +++ src/platform/keymaps/intellij-windows.ts | 11 +++ src/platform/locales/text/en.json | 3 + src/platform/locales/text/zh.json | 3 + 15 files changed, 342 insertions(+), 64 deletions(-) diff --git a/docs/en/guide/database.mdx b/docs/en/guide/database.mdx index fcc873338..a6d7a13da 100644 --- a/docs/en/guide/database.mdx +++ b/docs/en/guide/database.mdx @@ -146,7 +146,8 @@ Closing a selected result activates its left neighbor, or its right neighbor if **Edit Data** (`F4`) opens a table in an editor tab with server-side paging (100 to 5,000 rows), a `WHERE` filter and an `ORDER BY` field (both with completion). Click a column header to sort; `Shift`-click to add more sort columns. - Double-click, `Enter` or `F2` edits a cell; `Shift+Enter` opens a larger editor. Pasting tab-separated text fills several cells. -- **Add Row**, **Delete Rows**, **Set NULL** (`⌘⌫` / `Ctrl+Backspace`), **Set DEFAULT** (`⌘⇧⌫` / `Ctrl+Shift+Backspace`). `Space` toggles booleans. +- **Add Row** (`⌘N` / `Alt+Insert`), **Delete Rows** (`Ctrl+Y` on Windows and Linux), **Set NULL** (`⌘⌫` / `Ctrl+Backspace`), **Set DEFAULT** (`⌘⇧⌫` / `Ctrl+Shift+Backspace`). `Space` toggles booleans. +- **Reload Page** (`⌘R` / `Ctrl+F5`), **Previous Page** and **Next Page** (`⌘⌥↑` / `⌘⌥↓`, `Ctrl+Alt+Up` / `Ctrl+Alt+Down`). These, the copy commands and **Export Data** are actions: find them with **Find Action** and assign shortcuts in **Settings › Keymap**. - **Submit** (`⌘Enter` / `Ctrl+Enter`) sends all pending changes in one transaction; **Revert** (`⌘⌥Z` / `Ctrl+Alt+Z`) discards them. Console results are editable the same way when the query is a plain select from one table that includes the primary key. Tables without a primary key, joins, aggregates, `UNION` queries, read-only data sources and ClickHouse results are read-only. diff --git a/docs/zh/guide/database.mdx b/docs/zh/guide/database.mdx index c98995919..437a66b35 100644 --- a/docs/zh/guide/database.mdx +++ b/docs/zh/guide/database.mdx @@ -145,7 +145,8 @@ SQL 补全基于已连接的架构:`FROM`/`JOIN` 后补全表(并根据外 **编辑数据**(`F4`)在编辑器标签页中打开表,服务器端分页(每页 100 到 5,000 行),并提供 `WHERE` 过滤和 `ORDER BY` 字段(都支持补全)。点击列标题排序,按住 `Shift` 点击可以追加排序列。 - 双击、`Enter` 或 `F2` 编辑单元格;`Shift+Enter` 打开更大的编辑框。粘贴制表符分隔的文本可以一次填写多个单元格。 -- **添加行**、**删除行**、**设为 NULL**(`⌘⌫` / `Ctrl+Backspace`)、**设为默认值**(`⌘⇧⌫` / `Ctrl+Shift+Backspace`)。`Space` 切换布尔值。 +- **添加行**(`⌘N` / `Alt+Insert`)、**删除行**(Windows 和 Linux 上为 `Ctrl+Y`)、**设为 NULL**(`⌘⌫` / `Ctrl+Backspace`)、**设为默认值**(`⌘⇧⌫` / `Ctrl+Shift+Backspace`)。`Space` 切换布尔值。 +- **重新加载页面**(`⌘R` / `Ctrl+F5`)、**上一页** 和 **下一页**(`⌘⌥↑` / `⌘⌥↓`,`Ctrl+Alt+Up` / `Ctrl+Alt+Down`)。这些命令、各种复制命令和 **导出数据** 都是操作:可以在 **查找操作** 中找到,并在 **设置 › 按键映射** 中设置快捷键。 - **提交**(`⌘Enter` / `Ctrl+Enter`)在一个事务中提交所有待定更改;**还原**(`⌘⌥Z` / `Ctrl+Alt+Z`)放弃更改。 如果控制台查询是对单表的简单 select 且包含主键,结果同样可以编辑。没有主键的表、连接查询、聚合、`UNION` 查询、只读数据源和 ClickHouse 的结果都是只读的。 diff --git a/src/features/database/Grid.tsx b/src/features/database/Grid.tsx index 8c9fcc7a7..bb0e91781 100644 --- a/src/features/database/Grid.tsx +++ b/src/features/database/Grid.tsx @@ -409,6 +409,23 @@ export function Grid(props: GridProps) { const anchor = scrollRef.current?.querySelectorAll("[data-column-filter]")[sel!.c1]; if (anchor) props.onFilter!(sel!.c1, anchor); }, + canEditCell: () => { + if (!canEdit()) return false; + const n = norm(sel!); + return n.top === n.bottom && n.left === n.right && props.rowState?.(n.top) !== "deleted"; + }, + editCell: () => { + if (actions.canEditCell()) startEdit(sel!.r1, sel!.c1); + }, + hasSelection: () => !!sel && !editing, + copy: (kind) => { + if (!actions.hasSelection()) return; + if (kind === "header") copy("tsv", true); + else if (kind === "rowsTsv") copy("tsv", true, true); + else if (kind === "rowsCsv") copy("csv", true, true); + else copy(kind, false); + }, + selectedRows, }; Object.assign((cellActions.current ??= {} as CellActions), actions); }); @@ -529,20 +546,19 @@ export function Grid(props: GridProps) { { label: "Copy as", submenu: [ - { label: "TSV", verbatim: true, run: () => copy("tsv", false) }, - { label: "CSV", verbatim: true, run: () => copy("csv", false) }, - { label: "One-Row", run: () => copy("onerow", false) }, + { kind: "action", action: "db.copyAsTsv", label: "TSV", arg: cellActions.current }, + { kind: "action", action: "db.copyAsCsv", label: "CSV", arg: cellActions.current }, + { kind: "action", action: "db.copyAsOneRow", label: "One-Row", arg: cellActions.current }, ], }, - { label: "Copy with Header", run: () => copy("tsv", true) }, - { label: "Copy Rows as TSV", run: () => copy("tsv", true, true) }, - { label: "Copy Rows as CSV", run: () => copy("csv", true, true) }, + { kind: "action", action: "db.copyWithHeader", arg: cellActions.current }, + { kind: "action", action: "db.copyRowsAsTsv", arg: cellActions.current }, + { kind: "action", action: "db.copyRowsAsCsv", arg: cellActions.current }, ]; if (editable && onEdit) { - const n = norm(sel); items.push( { kind: "separator" }, - { label: "Edit Cell", disabled: n.top !== n.bottom || n.left !== n.right, run: () => startEdit(n.top, n.left) }, + { kind: "action", action: "db.editCell", arg: cellActions.current }, { kind: "action", action: "db.setCellNull", arg: cellActions.current }, { kind: "action", action: "db.setCellDefault", arg: cellActions.current }, ); diff --git a/src/features/database/ResultsView.tsx b/src/features/database/ResultsView.tsx index 75fe24c7f..396caf3c9 100644 --- a/src/features/database/ResultsView.tsx +++ b/src/features/database/ResultsView.tsx @@ -137,7 +137,8 @@ function readonlyNotice(reason: EditBlockReason): string { } /** IDEA's pager at the bottom of a result: |< < 1-500 of 501+ > >| and the page size; paging runs the query again. */ -function Pager({ tab }: { tab: ResultTab }) { +/** The result tab's page position and the page moves it allows, shared by the pager and the `db.*Page` actions. */ +function pagerOf(tab: ResultTab) { const r = tab.outcome.result!; const page = tab.page ?? 0; const pageSize = tab.pageSize ?? Math.max(r.rows.length, 1); @@ -154,6 +155,21 @@ function Pager({ tab }: { tab: ResultTab }) { } if (lastPage !== null && lastPage !== page) go(lastPage); }; + return { + page, + pageSize, + w, + canPage, + go, + goLast, + canPrevious: canPage && page > 0, + canNext: canPage && r.hasMore, + canLast: canPage && !((!r.hasMore && w.total !== null) || (w.total === null && !countable(tab))), + }; +} + +function Pager({ tab }: { tab: ResultTab }) { + const { page, pageSize, w, canPage, go, goLast, canPrevious, canNext, canLast } = pagerOf(tab); const { first, last } = w; const total = w.total === null ? `${w.last + 1}+` : String(w.total); const sizes = PAGE_SIZES.includes(pageSize) ? PAGE_SIZES : [...PAGE_SIZES, pageSize].sort((a, b) => a - b); @@ -162,15 +178,17 @@ function Pager({ tab }: { tab: ResultTab }) { go(0)} /> go(page - 1)} />