Skip to content

Build your personal knowledge base with Trilium Notes

client/text editor/tables: hide the row/column selection grid for table creation on mobile

Adorian Dorande6a359f757e
diff --git a/apps/client/src/widgets/type_widgets/text/toolbar.spec.ts b/apps/client/src/widgets/type_widgets/text/toolbar.spec.ts
index d169e9c87f..78c851bc84 100644
--- a/apps/client/src/widgets/type_widgets/text/toolbar.spec.ts
+++ b/apps/client/src/widgets/type_widgets/text/toolbar.spec.ts
@@ -133,6 +133,13 @@ describe("buildMobileToolbar", () => {
// No nested group objects survive the flattening.
expect(mobile.toolbar.items.some((item) => typeof item === "object")).toBe(false);
});
+
+ it("opens the table form instead of the size grid", () => {
+ const items = buildMobileToolbar(true).toolbar.items;
+ expect(items).toContain("insertTableForm");
+ expect(items).not.toContain("insertTable");
+ expect(buildClassicToolbar(false, true).toolbar.items).toContain("insertTable");
+ });
});
describe("buildToolbarConfig dispatch", () => {
diff --git a/apps/client/src/widgets/type_widgets/text/toolbar.ts b/apps/client/src/widgets/type_widgets/text/toolbar.ts
index 9213b0f574..470d0941a2 100644
--- a/apps/client/src/widgets/type_widgets/text/toolbar.ts
+++ b/apps/client/src/widgets/type_widgets/text/toolbar.ts
@@ -52,7 +52,8 @@ export function buildMobileToolbar(aiAssistant: boolean) {
items.push(subitem);
}
} else {
- items.push(item);
+ // The size grid of `insertTable` needs a pointer that hovers over its cells.
+ items.push(item === "insertTable" ? "insertTableForm" : item);
}
}
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Tables.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Tables.html
index e8c043a663..1c3aa961fd 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Tables.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Tables.html
@@ -19,6 +19,9 @@
<p>To close the form without inserting a table, press <kbd>Esc</kbd> or click
outside it. From the keyboard, <kbd>Tab</kbd> moves between <em>Insert table…</em> and
the grid while the menu is open.</p>
+<p>On the <a class="reference-link" href="#root/_help_RDslemsQ6gCp">Mobile Frontend</a>,
+ the <span class="tn-icon cke cke-table"></span>button opens the form directly,
+ without the grid.</p>
<h2>Formatting toolbar</h2>
<p>When a table is selected, a special formatting toolbar will appear:</p>
<img
diff --git a/docs/User Guide/User Guide/Note Types/Text/Tables.md b/docs/User Guide/User Guide/Note Types/Text/Tables.md
index 93cf835fe2..3a0c7fc86f 100644
--- a/docs/User Guide/User Guide/Note Types/Text/Tables.md
+++ b/docs/User Guide/User Guide/Note Types/Text/Tables.md
@@ -13,6 +13,8 @@ Since v0.107.0, the same menu starts with an _Insert table…_ item, for a table
To close the form without inserting a table, press <kbd>Esc</kbd> or click outside it. From the keyboard, <kbd>Tab</kbd> moves between _Insert table…_ and the grid while the menu is open.
+On the <a class="reference-link" href="../../Installation%20%26%20Setup/Mobile%20Frontend.md">Mobile Frontend</a>, the <span class="tn-icon cke cke-table"></span>button opens the form directly, without the grid.
+
## Formatting toolbar
When a table is selected, a special formatting toolbar will appear:
diff --git a/packages/ckeditor5/src/plugins/table_insert/table_insert_ui.spec.ts b/packages/ckeditor5/src/plugins/table_insert/table_insert_ui.spec.ts
index ec22ef4b8c..83dfe17078 100644
--- a/packages/ckeditor5/src/plugins/table_insert/table_insert_ui.spec.ts
+++ b/packages/ckeditor5/src/plugins/table_insert/table_insert_ui.spec.ts
@@ -2,6 +2,7 @@ import {
_getModelData as getModelData,
_setModelData as setModelData,
BlockToolbar,
+ ButtonView,
ClassicEditor,
ContextualBalloon,
DropdownView,
@@ -41,7 +42,7 @@ describe("TableInsertUI", () => {
beforeEach(async () => {
editor = await createTestEditor([Essentials, Paragraph, Table, TableInsertUI], {
- toolbar: ["insertTable"]
+ toolbar: ["insertTable", "insertTableForm"]
});
balloon = editor.plugins.get(ContextualBalloon);
setModelData(editor.model, "<paragraph>foo[]</paragraph>");
@@ -140,6 +141,24 @@ describe("TableInsertUI", () => {
});
});
+ describe("form button", () => {
+ it("opens the form, and is enabled with the insertTable command", async () => {
+ const button = editor.ui.view.toolbar.items.get(1);
+ expect(button).toBeInstanceOf(ButtonView);
+ expect(button).toMatchObject({ label: "Insert table", icon: IconTable, tooltip: true });
+
+ editor.enableReadOnlyMode("spec");
+ expect(button).toHaveProperty("isEnabled", false);
+ editor.disableReadOnlyMode("spec");
+ expect(button).toHaveProperty("isEnabled", true);
+
+ await userEvent.click(getElement(button as ButtonView));
+ const form = getForm(balloon);
+ expect(getInput(form, "columns").value).toBe(String(DEFAULT_TABLE_SIZE));
+ expect(document.activeElement).toBe(getInput(form, "rows"));
+ });
+ });
+
describe("form", () => {
it("opens at the caret when Insert table… is clicked", async () => {
const dropdown = getToolbarDropdown(editor);
diff --git a/packages/ckeditor5/src/plugins/table_insert/table_insert_ui.ts b/packages/ckeditor5/src/plugins/table_insert/table_insert_ui.ts
index be50ca54eb..6bc500163b 100644
--- a/packages/ckeditor5/src/plugins/table_insert/table_insert_ui.ts
+++ b/packages/ckeditor5/src/plugins/table_insert/table_insert_ui.ts
@@ -32,7 +32,8 @@ import TableInsertFormView from "./table_insert_form.js";
/**
* Replaces the `insertTable` dropdown with one that has an "Insert table…" button above the size
* grid. The button opens {@link TableInsertFormView} in a balloon at the caret, where the number
- * of rows and columns is typed.
+ * of rows and columns is typed. The `insertTableForm` toolbar button opens the form directly, for
+ * touch screens, where the size grid cannot be hovered.
*/
export default class TableInsertUI extends Plugin {
@@ -49,6 +50,9 @@ export default class TableInsertUI extends Plugin {
init() {
// Replaces the dropdown of `TableUI`, which `Table` initializes before this plugin.
this.editor.ui.componentFactory.add("insertTable", (locale) => this.createDropdown(locale));
+ this.editor.ui.componentFactory.add("insertTableForm", (locale) => {
+ return this.createFormButton(locale);
+ });
}
override destroy() {
@@ -129,6 +133,22 @@ export default class TableInsertUI extends Plugin {
return dropdownView;
}
+ private createFormButton(locale: Locale): ButtonView {
+ // Always registered: `Table` loads `TableEditing`.
+ const command = this.editor.commands.get("insertTable") as InsertTableCommand;
+ const button = new ButtonView(locale);
+
+ button.bind("isEnabled").to(command);
+ button.set({
+ icon: IconTable,
+ label: this.editor.t("Insert table"),
+ tooltip: true
+ });
+ button.on("execute", () => this.showForm());
+
+ return button;
+ }
+
private getFormView(): TableInsertFormView {
if (this.formView) {
return this.formView;