Skip to content

Build your personal knowledge base with Trilium Notes

client/text editor/tables: invert the order of row/columns fields in the new table popover

Adorian Dorane042eb672095
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 1c3aa961fd..9a9ad3d5b1 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
@@ -11,8 +11,8 @@
<ol>
<li>Click the <span class="tn-icon cke cke-table"></span>button and select <em>Insert table…</em>.
A small form opens at the cursor.</li>
- <li>Enter the number of <em>Rows</em> (up to 1000) and <em>Columns</em> (up to
- 100). The table can have at most 5000 cells in total, for example 1000
+ <li>Enter the number of <em>Columns</em> (up to 100) and <em>Rows</em> (up to
+ 1000). The table can have at most 5000 cells in total, for example 1000
rows of 5 columns.</li>
<li>Press <em>Insert</em> or <kbd>Enter</kbd>.</li>
</ol>
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 3a0c7fc86f..4219e2142b 100644
--- a/docs/User Guide/User Guide/Note Types/Text/Tables.md
+++ b/docs/User Guide/User Guide/Note Types/Text/Tables.md
@@ -8,7 +8,7 @@ To create a table, simply press the table button and select with the mouse the d
Since v0.107.0, the same menu starts with an _Insert table…_ item, for a table larger than the grid or to type its size instead:
1. Click the <span class="tn-icon cke cke-table"></span>button and select _Insert table…_. A small form opens at the cursor.
-2. Enter the number of _Rows_ (up to 1000) and _Columns_ (up to 100). The table can have at most 5000 cells in total, for example 1000 rows of 5 columns.
+2. Enter the number of _Columns_ (up to 100) and _Rows_ (up to 1000). The table can have at most 5000 cells in total, for example 1000 rows of 5 columns.
3. Press _Insert_ or <kbd>Enter</kbd>.
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.
diff --git a/packages/ckeditor5/src/plugins/table_insert/table_insert_form.spec.ts b/packages/ckeditor5/src/plugins/table_insert/table_insert_form.spec.ts
index 4e16b8b2d5..a5daed2452 100644
--- a/packages/ckeditor5/src/plugins/table_insert/table_insert_form.spec.ts
+++ b/packages/ckeditor5/src/plugins/table_insert/table_insert_form.spec.ts
@@ -42,12 +42,12 @@ describe("TableInsertFormView", () => {
form.destroy();
});
- it("renders the Rows and Columns fields and a submit button", () => {
+ it("renders the Columns and Rows fields and a submit button", () => {
const element = getElement(form);
expect(element.tagName).toBe("FORM");
expect(element.getAttribute("aria-label")).toBe("Insert table");
- const [rowsLabel, columnsLabel] = Array.from(element.querySelectorAll("label"));
+ const [columnsLabel, rowsLabel] = Array.from(element.querySelectorAll("label"));
expect(rowsLabel.textContent).toBe("Rows");
expect(columnsLabel.textContent).toBe("Columns");
expect(rowsLabel.htmlFor).toBe(getInput(form.rowsField).id);
@@ -106,7 +106,7 @@ describe("TableInsertFormView", () => {
expect(error.getAttribute("role")).toBe("alert");
expectValid(form.rowsField);
expectValid(form.columnsField);
- expect(document.activeElement).toBe(getInput(form.rowsField));
+ expect(document.activeElement).toBe(getInput(form.columnsField));
});
it("clears the size error when either field is edited", async () => {
@@ -141,7 +141,7 @@ describe("TableInsertFormView", () => {
expect(form.validate()).toBeNull();
expectInvalid(form.rowsField);
expectInvalid(form.columnsField);
- expect(document.activeElement).toBe(getInput(form.rowsField));
+ expect(document.activeElement).toBe(getInput(form.columnsField));
});
it("clears the error of a field when its value is edited", async () => {
@@ -173,12 +173,12 @@ describe("TableInsertFormView", () => {
expect(form.validate()).toEqual({ rows: DEFAULT_TABLE_SIZE, columns: DEFAULT_TABLE_SIZE });
});
- it("focus() focuses the Rows field and selects its value", () => {
- const select = vi.spyOn(form.rowsField.inputView, "select");
+ it("focus() focuses the Columns field and selects its value", () => {
+ const select = vi.spyOn(form.columnsField.inputView, "select");
form.focus();
- expect(document.activeElement).toBe(getInput(form.rowsField));
+ expect(document.activeElement).toBe(getInput(form.columnsField));
expect(select).toHaveBeenCalled();
});
@@ -186,11 +186,11 @@ describe("TableInsertFormView", () => {
form.focus();
await userEvent.keyboard("{Tab}");
- expect(document.activeElement).toBe(getInput(form.columnsField));
+ expect(document.activeElement).toBe(getInput(form.rowsField));
await userEvent.keyboard("{Tab}");
expect(document.activeElement).toBe(getElement(form.insertButtonView));
await userEvent.keyboard("{Tab}");
- expect(document.activeElement).toBe(getInput(form.rowsField));
+ expect(document.activeElement).toBe(getInput(form.columnsField));
await userEvent.keyboard("{Shift>}{Tab}{/Shift}");
expect(document.activeElement).toBe(getElement(form.insertButtonView));
});
diff --git a/packages/ckeditor5/src/plugins/table_insert/table_insert_form.ts b/packages/ckeditor5/src/plugins/table_insert/table_insert_form.ts
index da59342751..07e9885214 100644
--- a/packages/ckeditor5/src/plugins/table_insert/table_insert_form.ts
+++ b/packages/ckeditor5/src/plugins/table_insert/table_insert_form.ts
@@ -30,7 +30,7 @@ export interface TableSize {
}
/**
- * The balloon form behind "Insert table…": a "Rows" field, a "Columns" field and an Insert button.
+ * The balloon form behind "Insert table…": a "Columns" field, a "Rows" field and an Insert button.
* Invalid values are reported under their field when the form is submitted, and a table with more
* than {@link MAX_TABLE_CELLS} cells is reported above the button.
*/
@@ -79,8 +79,8 @@ export default class TableInsertFormView extends View {
novalidate: true
},
children: [
- this.rowsField,
this.columnsField,
+ this.rowsField,
{
tag: "div",
attributes: {
@@ -99,7 +99,7 @@ export default class TableInsertFormView extends View {
});
// The size error is cleared as soon as either value is edited.
- for (const field of [this.rowsField, this.columnsField]) {
+ for (const field of [this.columnsField, this.rowsField]) {
field.inputView.on("input", () => {
this.sizeErrorText = null;
});
@@ -122,8 +122,8 @@ export default class TableInsertFormView extends View {
// Turns a native form submit, the Enter key included, into the view's `submit` event.
submitHandler({ view: this });
- const { rowsField, columnsField, insertButtonView } = this;
- for (const view of [rowsField.inputView, columnsField.inputView, insertButtonView]) {
+ const { columnsField, rowsField, insertButtonView } = this;
+ for (const view of [columnsField.inputView, rowsField.inputView, insertButtonView]) {
this.focusables.add(view);
/* v8 ignore next -- a child view rendered as part of this template has an element */
if (view.element) {
@@ -143,10 +143,10 @@ export default class TableInsertFormView extends View {
this.keystrokes.destroy();
}
- /** Focuses the "Rows" field and selects its value. */
+ /** Focuses the "Columns" field and selects its value. */
public focus(): void {
this.focusCycler.focusFirst();
- this.rowsField.inputView.select();
+ this.columnsField.inputView.select();
}
/** Sets both fields to {@link DEFAULT_TABLE_SIZE} and clears the errors. */
@@ -162,20 +162,20 @@ export default class TableInsertFormView extends View {
*/
public validate(): TableSize | null {
this.sizeErrorText = null;
- const rows = this.rowsField.validate();
const columns = this.columnsField.validate();
+ const rows = this.rowsField.validate();
- if (rows === null) {
- this.rowsField.focus();
- return null;
- }
if (columns === null) {
this.columnsField.focus();
return null;
}
+ if (rows === null) {
+ this.rowsField.focus();
+ return null;
+ }
if (rows * columns > MAX_TABLE_CELLS) {
this.sizeErrorText = this.tooLargeText;
- this.rowsField.focus();
+ this.columnsField.focus();
return null;
}
return { rows, columns };
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 83dfe17078..f0a50ba8be 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
@@ -137,7 +137,8 @@ describe("TableInsertUI", () => {
await userEvent.keyboard("{Enter}");
expect(dropdown.isOpen).toBe(false);
- expect(document.activeElement).toBe(getForm(balloon).rowsField.inputView.element);
+ expect(document.activeElement)
+ .toBe(getForm(balloon).columnsField.inputView.element);
});
});
@@ -155,7 +156,7 @@ describe("TableInsertUI", () => {
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"));
+ expect(document.activeElement).toBe(getInput(form, "columns"));
});
});
@@ -170,7 +171,7 @@ describe("TableInsertUI", () => {
const form = getForm(balloon);
expect(getInput(form, "rows").value).toBe(String(DEFAULT_TABLE_SIZE));
expect(getInput(form, "columns").value).toBe(String(DEFAULT_TABLE_SIZE));
- expect(document.activeElement).toBe(getInput(form, "rows"));
+ expect(document.activeElement).toBe(getInput(form, "columns"));
// The balloon points at the caret, after "foo".
const caret = getCaretRect(editor);
@@ -225,14 +226,14 @@ describe("TableInsertUI", () => {
expect(balloon.visibleView).toBe(form);
expect(form.rowsField.errorText).not.toBeNull();
expect(form.columnsField.errorText).not.toBeNull();
- expect(document.activeElement).toBe(getInput(form, "rows"));
+ expect(document.activeElement).toBe(getInput(form, "columns"));
- await userEvent.fill(getInput(form, "rows"), "3");
+ await userEvent.fill(getInput(form, "columns"), "4");
await userEvent.keyboard("{Enter}");
expect(getTableSize(editor)).toBeNull();
- expect(document.activeElement).toBe(getInput(form, "columns"));
+ expect(document.activeElement).toBe(getInput(form, "rows"));
- await userEvent.fill(getInput(form, "columns"), "4");
+ await userEvent.fill(getInput(form, "rows"), "3");
await userEvent.keyboard("{Enter}");
expect(getTableSize(editor)).toEqual({ rows: 3, columns: 4 });
});
@@ -251,7 +252,7 @@ describe("TableInsertUI", () => {
expect(message?.textContent)
.toBe(`The table is too large (max ${MAX_TABLE_CELLS} cells).`);
expect(message?.checkVisibility()).toBe(true);
- expect(document.activeElement).toBe(getInput(form, "rows"));
+ expect(document.activeElement).toBe(getInput(form, "columns"));
await userEvent.fill(getInput(form, "rows"), "100");
expect(message?.checkVisibility()).toBe(false);
@@ -352,7 +353,7 @@ describe("TableInsertUI", () => {
const form = getForm(translated.plugins.get(ContextualBalloon));
const labels = Array.from(getElement(form).querySelectorAll("label"))
.map((label) => label.textContent);
- expect(labels).toEqual(["Rânduri", "Coloane"]);
+ expect(labels).toEqual(["Coloane", "Rânduri"]);
getInput(form, "rows").value = "0";
form.validate();
@@ -378,7 +379,7 @@ describe("TableInsertUI", () => {
expect(blockToolbar.panelView.isVisible).toBe(false);
const form = getForm(blockEditor.plugins.get(ContextualBalloon));
- expect(document.activeElement).toBe(getInput(form, "rows"));
+ expect(document.activeElement).toBe(getInput(form, "columns"));
});
});
});