Skip to content

Build your personal knowledge base with Trilium Notes

client/text editor/tables: make the table column bar be able to resize just the active column

Adorian Doran43667da71d92
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 eb1afea44e..e8c043a663 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
@@ -163,20 +163,27 @@ src="3_Tables_image.png" width="384" height="100">
<h3>Resizing with touch</h3>
<p>Since v0.107.0, touching a table shows a bar at the bottom of the note,
above the formatting toolbar on mobile. The bar has a segment for each
- column of the table, with a divider at the end of each column.</p>
+ column of the table, with a divider at the end of each column. Only the
+ divider of the column with the cursor is a handle that resizes; the other
+ dividers only mark where the columns meet, so a swipe across them scrolls
+ instead. When several cells are selected, each column they cover has a
+ handle.</p>
<ul>
- <li>To resize a column, drag its divider. The table grows or shrinks with
- the column, and scrolls when the divider reaches the edge of the screen.
- The column snaps to its starting width and to the widths of the columns
- beside it.</li>
- <li>To cancel a resize, drag the divider back to where it started, or touch
+ <li>To resize a column, place the cursor in one of its cells or tap its segment,
+ then drag its handle. The table grows or shrinks with the column, and scrolls
+ when the handle reaches the edge of the screen. The column snaps to its
+ starting width and to the widths of the columns beside it.</li>
+ <li>To cancel a resize, drag the handle back to where it started, or touch
the screen with a second finger.</li>
- <li>To give two neighboring columns the same width, double-tap the divider
+ <li>To give a column and the next one the same width, double-tap the handle
between them.</li>
<li>To select a column, tap its segment. To open the column menu, touch and
hold the segment.</li>
<li>To scroll a wide table sideways, swipe along the bar.</li>
</ul>
+<p>A wide table scrolls a little past its end, so the handle of its last
+ column stays away from the edge of the screen, where a swipe navigates
+ back.</p>
<h2>Wide tables</h2>
<p>Since v0.107.0, a table can be wider than the&nbsp;<a class="reference-link"
href="#root/_help_t596jLvPrqkS">Content width</a>. Such a table scrolls
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 bfcc12392e..93cf835fe2 100644
--- a/docs/User Guide/User Guide/Note Types/Text/Tables.md
+++ b/docs/User Guide/User Guide/Note Types/Text/Tables.md
@@ -74,14 +74,16 @@ Right-clicking a cell that is not part of the current selection moves the cursor
### Resizing with touch
-Since v0.107.0, touching a table shows a bar at the bottom of the note, above the formatting toolbar on mobile. The bar has a segment for each column of the table, with a divider at the end of each column.
+Since v0.107.0, touching a table shows a bar at the bottom of the note, above the formatting toolbar on mobile. The bar has a segment for each column of the table, with a divider at the end of each column. Only the divider of the column with the cursor is a handle that resizes; the other dividers only mark where the columns meet, so a swipe across them scrolls instead. When several cells are selected, each column they cover has a handle.
-* To resize a column, drag its divider. The table grows or shrinks with the column, and scrolls when the divider reaches the edge of the screen. The column snaps to its starting width and to the widths of the columns beside it.
-* To cancel a resize, drag the divider back to where it started, or touch the screen with a second finger.
-* To give two neighboring columns the same width, double-tap the divider between them.
+* To resize a column, place the cursor in one of its cells or tap its segment, then drag its handle. The table grows or shrinks with the column, and scrolls when the handle reaches the edge of the screen. The column snaps to its starting width and to the widths of the columns beside it.
+* To cancel a resize, drag the handle back to where it started, or touch the screen with a second finger.
+* To give a column and the next one the same width, double-tap the handle between them.
* To select a column, tap its segment. To open the column menu, touch and hold the segment.
* To scroll a wide table sideways, swipe along the bar.
+A wide table scrolls a little past its end, so the handle of its last column stays away from the edge of the screen, where a swipe navigates back.
+
## Wide tables
Since v0.107.0, a table can be wider than the <a class="reference-link" href="../../Basic%20Concepts%20and%20Features/UI%20Elements/Content%20width.md">Content width</a>. Such a table scrolls sideways, while the rest of the note keeps its width.
diff --git a/packages/ckeditor5/src/plugins/table_column_bar/table_column_bar.spec.ts b/packages/ckeditor5/src/plugins/table_column_bar/table_column_bar.spec.ts
index 06112d12b5..d516b69597 100644
--- a/packages/ckeditor5/src/plugins/table_column_bar/table_column_bar.spec.ts
+++ b/packages/ckeditor5/src/plugins/table_column_bar/table_column_bar.spec.ts
@@ -25,7 +25,7 @@ import {
} from "vitest";
import { createTestEditor, createTestEditorOf } from "../../../test/editor-kit.js";
-import { cellAt, modelTable } from "../../../test/table-kit.js";
+import { cellAt, modelTable, selectCells } from "../../../test/table-kit.js";
import type { CellSpec } from "../../../test/table-kit.js";
import { REFERENCE_WIDTH_PROPERTY } from "../table_scroll.js";
import TableColumnBar, { findSnapPoint, getCenteredGrowth } from "./table_column_bar.js";
@@ -222,6 +222,27 @@ describe("TableColumnBar", () => {
expectNear(barRectOf(other).bottom, document.documentElement.clientHeight);
}
});
+
+ it("leaves room after the end of a scrolling table while touch is in use", async () => {
+ const rtl = await createTestEditor(PLUGINS, { language: { content: "ar" } });
+ setEditableWidth(rtl, 400);
+ for (const each of [editor, rtl]) {
+ await showBar(each, modelTable([["a", "b[]"]], 'tableWidth="200%"'));
+ scrollToEnd(each);
+ await frames();
+ expectNear(roomAfterTable(each), 64);
+
+ // The last divider takes a press across its whole width.
+ const divider = dividers(each)[1];
+ const { x, y } = centerOf(divider);
+ expect(document.elementFromPoint(x + 10 * directionOf(each), y)).toBe(divider);
+ }
+
+ touch("mouse");
+ for (const each of [editor, rtl]) {
+ await expect.poll(() => roomAfterTable(each)).toBeLessThan(1);
+ }
+ });
});
describe("segments", () => {
@@ -322,9 +343,41 @@ describe("TableColumnBar", () => {
expect(getTableColumnsWidths(table)).toEqual([]);
});
+ it("resizes only the columns of the cells at the selection", async () => {
+ const rows = [["a", "b[]", "c"], ["d", "e", "f"]];
+ await showBar(editor, modelTable(rows, 'tableWidth="80%"'));
+ const table = firstTable(editor);
+ expect(resizableColumns(editor)).toEqual([1]);
+
+ // Another divider lets a press through to the segments, and ignores one sent to it.
+ const { x, y } = centerOf(dividers(editor)[0]);
+ const pressed = document.elementFromPoint(x, y);
+ expect(pressed?.classList.contains("ck-table-column-bar__segment")).toBe(true);
+ const resizable = centerOf(dividers(editor)[1]);
+ expect(document.elementFromPoint(resizable.x, resizable.y)).toBe(dividers(editor)[1]);
+ press(dividers(editor)[0]);
+ moveTo(x + 40, y);
+ release();
+ expect(getTableColumnsWidths(table)).toEqual([]);
+
+ press(segments(editor)[0]);
+ release();
+ await expect.poll(() => resizableColumns(editor)).toEqual([0]);
+
+ selectCells(editor, [0, 1], [1, 2]);
+ await expect.poll(() => resizableColumns(editor)).toEqual([1, 2]);
+
+ editor.model.change((writer) => writer.setSelection(table, "on"));
+ await expect.poll(() => resizableColumns(editor)).toEqual([]);
+
+ const merged = [[{ contents: "a[]", colspan: 2 }, "b"], ["c", "d", "e"]];
+ await showBar(editor, modelTable(merged));
+ await expect.poll(() => resizableColumns(editor)).toEqual([0, 1]);
+ });
+
it("keeps pixels for a table sized in pixels", async () => {
const widths = ["100px", "200px"];
- await showBar(editor, resizedTable([["a[]", "b"]], widths, 'tableWidth="300px"'));
+ await showBar(editor, resizedTable([["a", "b[]"]], widths, 'tableWidth="300px"'));
const table = firstTable(editor);
const edge = endEdgeOf(editor, 1);
@@ -361,7 +414,7 @@ describe("TableColumnBar", () => {
});
const referenced = await createTestEditor(PLUGINS);
setEditableWidth(referenced, 400);
- await showBar(referenced, modelTable([["a[]", "b"]], 'tableWidth="25%"'));
+ await showBar(referenced, modelTable([["a", "b[]"]], 'tableWidth="25%"'));
const edge = endEdgeOf(referenced, 1);
const { x, y } = press(dividers(referenced)[1]);
@@ -487,10 +540,29 @@ describe("TableColumnBar", () => {
expect(columnWidths(editor)[0]).toBeLessThan(grown);
});
+ it("keeps a scrolled table still while the last divider moves into the room", async () => {
+ await showBar(editor, modelTable([["a", "b[]"]], 'tableWidth="200%"'));
+ const figure = domFigure(editor);
+ scrollToEnd(editor);
+ await frames();
+ const scrolled = figure.scrollLeft;
+ const edge = endEdgeOf(editor, 1);
+
+ const { x, y } = press(dividers(editor)[1]);
+ moveTo(x + 16, y);
+ await frames();
+ await frames();
+ expect(figure.scrollLeft).toBe(scrolled);
+ expectNear(endEdgeOf(editor, 1), edge + 16);
+ release();
+ });
+
it("evens out the two columns beside a divider on a double tap", async () => {
const widths = ["100px", "200px", "100px"];
await showBar(editor, resizedTable([["a[]", "b", "c"]], widths, 'tableWidth="400px"'));
const table = firstTable(editor);
+ selectCells(editor, [0, 0], [0, 2]);
+ await expect.poll(() => resizableColumns(editor)).toEqual([0, 1, 2]);
tapDivider(editor, 0);
tapDivider(editor, 1);
@@ -532,12 +604,15 @@ describe("TableColumnBar", () => {
tapDivider(editor, 0);
const afterDrag = getTableColumnsWidths(first);
- tapDivider(editor, 1);
+ // Each section starts long after the last tap of the one before.
+ now.mockReturnValue(2000);
+ tapDivider(editor, 0);
press(segments(editor)[0]);
release();
- tapDivider(editor, 1);
+ tapDivider(editor, 0);
const afterPress = getTableColumnsWidths(first);
+ now.mockReturnValue(3000);
tapDivider(editor, 0);
editor.model.change((writer) => writer.setSelection(second.getNodeByPath([0, 0]), 0));
await frames();
@@ -598,10 +673,13 @@ function touch(pointerType = "touch") {
document.body.dispatchEvent(new PointerEvent("pointerdown", { bubbles: true, pointerType }));
}
-function press(element: Element, init: PointerEventInit = {}) {
+function centerOf(element: Element) {
const rect = element.getBoundingClientRect();
- const x = rect.left + rect.width / 2;
- const y = rect.top + rect.height / 2;
+ return { x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 };
+}
+
+function press(element: Element, init: PointerEventInit = {}) {
+ const { x, y } = centerOf(element);
element.dispatchEvent(new PointerEvent("pointerdown", {
bubbles: true,
cancelable: true,
@@ -644,6 +722,12 @@ function dividers(editor: Editor) {
return [...barView(editor).track.querySelectorAll<HTMLElement>(".ck-table-column-bar__divider")];
}
+function resizableColumns(editor: Editor) {
+ return dividers(editor)
+ .filter((divider) => divider.classList.contains("ck-table-column-bar__divider_resizable"))
+ .map((divider) => Number(divider.dataset.column));
+}
+
function edgeElementOf(editor: Editor) {
const edge = barView(editor).element?.querySelector(".ck-table-column-bar__edge");
if (!(edge instanceof HTMLElement)) {
@@ -710,6 +794,31 @@ function domCells(editor: Editor) {
return [...domFigure(editor).querySelectorAll<HTMLElement>("tr:first-child > td")];
}
+/** 1 when the inline end of a row is on the right, -1 when it is on the left. */
+function directionOf(editor: Editor) {
+ return editor.locale.contentLanguageDirection === "rtl" ? -1 : 1;
+}
+
+function scrollToEnd(editor: Editor) {
+ const figure = domFigure(editor);
+ figure.scrollLeft = figure.scrollWidth * directionOf(editor);
+}
+
+/** The distance from the inline end of the table to the inline end of its visible part. */
+function roomAfterTable(editor: Editor) {
+ const figure = domFigure(editor);
+ const table = figure.querySelector(":scope > table");
+ if (!table) {
+ throw new Error("The figure has no table.");
+ }
+
+ const left = figure.getBoundingClientRect().left + figure.clientLeft;
+ const tableRect = table.getBoundingClientRect();
+ return directionOf(editor) > 0
+ ? left + figure.clientWidth - tableRect.right
+ : tableRect.left - left;
+}
+
function columnWidths(editor: Editor) {
return domCells(editor).map((cell) => cell.getBoundingClientRect().width);
}
diff --git a/packages/ckeditor5/src/plugins/table_column_bar/table_column_bar.ts b/packages/ckeditor5/src/plugins/table_column_bar/table_column_bar.ts
index 4554b82cd2..4acdf6123e 100644
--- a/packages/ckeditor5/src/plugins/table_column_bar/table_column_bar.ts
+++ b/packages/ckeditor5/src/plugins/table_column_bar/table_column_bar.ts
@@ -17,6 +17,7 @@ import type { DropdownView, ModelElement, ToolbarView, ViewElement } from "ckedi
import {
distributeColumns,
+ getSpannedColumns,
getTableWidthBasis,
measureColumnEdges
} from "../table_distribute_columns.js";
@@ -29,7 +30,10 @@ import {
getViewportBottom
} from "../viewport_geometry.js";
import { trackPointer } from "./pointer_tracking.js";
-import TableColumnBarView from "./table_column_bar_view.js";
+import TableColumnBarView, {
+ HANDLE_SELECTOR,
+ RESIZABLE_DIVIDER_CLASS
+} from "./table_column_bar_view.js";
const LONG_PRESS_MS = 500;
const DOUBLE_TAP_MS = 400;
@@ -37,12 +41,15 @@ const VIBRATION_MS = 10;
/** The distance from a snap point at which a dragged width takes it, in pixels. */
const SNAP_DISTANCE = 8;
const RESIZED_TABLE_CLASS = "ck-table-resized";
+/** Set on the editable while touch is in use. Scrolling tables then end with a gap. */
+const TOUCH_CLASS = "ck-table-column-bar-touch";
/**
* A bar along the bottom of the editing area for the table at the selection, shown after a touch.
* Each segment is a column: a tap selects it, a long press opens the column menu and a swipe
- * scrolls the table. Dragging the divider at the end of a column resizes it, and the table grows
- * or shrinks with it. A double tap on a divider evens out the two columns beside it.
+ * scrolls the table. Dragging the divider at the end of a column of the selected cells resizes
+ * it, and the table grows or shrinks with it. A double tap on that divider evens out the two
+ * columns beside it.
*/
export default class TableColumnBar extends Plugin {
@@ -53,7 +60,7 @@ export default class TableColumnBar extends Plugin {
private edges: number[] | null = null;
private isMeasureNeeded = true;
private frame = 0;
- /** The visible part of the table in the viewport, in pixels. */
+ /** The visible part of the table's horizontal scroller in the viewport, in pixels. */
private trackBox = { left: 0, right: 0 };
private bottomOffset = 0;
private resizedColumn: number | null = null;
@@ -101,12 +108,15 @@ export default class TableColumnBar extends Plugin {
this.domEmitter.listenTo(viewport, "resize", () => this.scheduleUpdate(false));
}
- // The columns are measured again only when the content or the size of the table changes.
+ // The columns are measured again only when the content, the selection or the size of
+ // the table changes.
const update = () => this.scheduleUpdate(false);
+ const measure = () => this.scheduleUpdate(true);
this.listenTo(editor.ui, "update", update);
this.listenTo(editor.ui.focusTracker, "change:isFocused", update);
this.listenTo(editor, "change:isReadOnly", update);
- this.listenTo(editor.model.document, "change:data", () => this.scheduleUpdate(true));
+ this.listenTo(editor.model.document, "change:data", measure);
+ this.listenTo(editor.model.document.selection, "change:range", measure);
}
override destroy() {
@@ -161,10 +171,24 @@ export default class TableColumnBar extends Plugin {
const isOnBar = !!(event.target as Element).closest(".ck-table-column-bar");
if (isTouch !== this.isTouch && !isOnBar) {
this.isTouch = isTouch;
+ this.setTouchClass(isTouch);
this.scheduleUpdate(true);
}
}
+ private setTouchClass(isTouch: boolean) {
+ const view = this.editor.editing.view;
+ view.change((writer) => {
+ for (const root of view.document.roots) {
+ if (isTouch) {
+ writer.addClass(TOUCH_CLASS, root);
+ } else {
+ writer.removeClass(TOUCH_CLASS, root);
+ }
+ }
+ });
+ }
+
private findTarget(): BarTarget | null {
const editor = this.editor;
if (!this.isTouch || editor.isReadOnly || !editor.ui.focusTracker.isFocused) {
@@ -207,8 +231,10 @@ export default class TableColumnBar extends Plugin {
const barTop = area.bottom - view.track.offsetHeight;
const tableRect = target.domTable.getBoundingClientRect();
const clip = getClientBox(findScroller(target.domTable, "overflowX"));
- const left = Math.max(tableRect.left, clip.left, area.left);
- const right = Math.min(tableRect.right, clip.right, area.right);
+ const trackLeft = Math.max(clip.left, area.left);
+ const trackRight = Math.min(clip.right, area.right);
+ const left = Math.max(tableRect.left, trackLeft);
+ const right = Math.min(tableRect.right, trackRight);
const top = Math.max(tableRect.top, clip.top, area.top);
const bottom = Math.min(tableRect.bottom, clip.bottom, barTop);
if (right <= left || bottom <= top) {
@@ -221,9 +247,11 @@ export default class TableColumnBar extends Plugin {
return null;
}
+ // The track spans the scroller, so the divider at the table's end shows in full and the
+ // auto-scroll starts only near the edges of the scroller.
view.set({ left: area.left, top: barTop, width: area.right - area.left });
- view.setTrack(left - area.left, right - left, tableRect.left - left);
- this.trackBox = { left, right };
+ view.setTrack(trackLeft - area.left, trackRight - trackLeft, tableRect.left - trackLeft);
+ this.trackBox = { left: trackLeft, right: trackRight };
const column = this.resizedColumn;
view.setActiveDivider(column);
@@ -233,15 +261,19 @@ export default class TableColumnBar extends Plugin {
return barTop;
}
- /** The column boundaries of the target table, measured again when its layout can differ. */
+ /**
+ * The column boundaries of the target table, measured again when its layout or the selection
+ * can differ.
+ */
private measure(target: BarTarget, tableRect: DOMRect) {
if (this.edges && !this.isMeasureNeeded) {
return this.edges;
}
const editor = this.editor;
+ const tableUtils = editor.plugins.get(TableUtils);
const isRtl = editor.locale.contentLanguageDirection === "rtl";
- const columnCount = editor.plugins.get(TableUtils).getColumns(target.table);
+ const columnCount = tableUtils.getColumns(target.table);
const measured = measureColumnEdges(editor, target.table, columnCount);
/* v8 ignore next 3 -- defensive: the bar shows a rendered table */
if (!measured) {
@@ -257,7 +289,8 @@ export default class TableColumnBar extends Plugin {
labels.push(editor.t("Column %0 width: %1%", [column + 1, share]));
}
- this.view.setColumns(edges, labels);
+ const cells = tableUtils.getSelectionAffectedTableCells(editor.model.document.selection);
+ this.view.setColumns(edges, labels, getSpannedColumns(target.table, cells));
this.edges = edges;
this.isMeasureNeeded = false;
return edges;
@@ -282,7 +315,7 @@ export default class TableColumnBar extends Plugin {
private onPointerDown(event: PointerEvent) {
const target = this.target;
- const handle = (event.target as Element).closest<HTMLElement>("[data-column]");
+ const handle = (event.target as Element).closest<HTMLElement>(HANDLE_SELECTOR);
if (!target || !handle || !event.isPrimary) {
return;
}
@@ -296,7 +329,7 @@ export default class TableColumnBar extends Plugin {
const previousTap = this.lastTap;
this.lastTap = null;
const column = Number(handle.dataset.column);
- if (handle.classList.contains("ck-table-column-bar__divider")) {
+ if (handle.classList.contains(RESIZABLE_DIVIDER_CLASS)) {
this.startResize(event, column, target, previousTap);
} else {
this.startPress(event, column, target);
diff --git a/packages/ckeditor5/src/plugins/table_column_bar/table_column_bar_view.ts b/packages/ckeditor5/src/plugins/table_column_bar/table_column_bar_view.ts
index fdd431a49d..e6a525f4a3 100644
--- a/packages/ckeditor5/src/plugins/table_column_bar/table_column_bar_view.ts
+++ b/packages/ckeditor5/src/plugins/table_column_bar/table_column_bar_view.ts
@@ -1,7 +1,13 @@
import { type DropdownView, type Locale, toUnit, View, type ViewCollection } from "ckeditor5";
+import type { IndexRange } from "../table_move/table_move_groups.js";
+
+const SEGMENT_CLASS = "ck-table-column-bar__segment";
const DIVIDER_CLASS = "ck-table-column-bar__divider";
const ACTIVE_DIVIDER_CLASS = "ck-table-column-bar__divider_active";
+export const RESIZABLE_DIVIDER_CLASS = "ck-table-column-bar__divider_resizable";
+/** The elements of the bar that start a gesture. */
+export const HANDLE_SELECTOR = `.${SEGMENT_CLASS}, .${RESIZABLE_DIVIDER_CLASS}`;
/** The place of the edge line in the viewport, in pixels. */
export interface EdgeBox {
@@ -22,7 +28,7 @@ export default class TableColumnBarView extends View<HTMLDivElement> {
declare width: number;
declare menuLeft: number;
- /** The visible part of the table, where the gestures start. */
+ /** The visible part of the table's horizontal scroller, where the gestures start. */
readonly track = createElement("ck-table-column-bar__track");
readonly menus: ViewCollection<DropdownView>;
/** The segments and dividers, positioned from the left edge of the table. */
@@ -72,8 +78,8 @@ export default class TableColumnBarView extends View<HTMLDivElement> {
}
/**
- * Shows the part of the table from `left` to `left + width` of the bar. `offset` is the
- * position of the table's left edge in that part.
+ * Shows the columns from `left` to `left + width` of the bar. `offset` is the position of the
+ * table's left edge in that part.
*/
setTrack(left: number, width: number, offset: number) {
this.track.style.left = `${left}px`;
@@ -83,13 +89,14 @@ export default class TableColumnBarView extends View<HTMLDivElement> {
/**
* Draws a segment between each two of `edges`, in pixels from the table's left edge, and a
- * divider labeled from `labels` at the end of each segment.
+ * divider labeled from `labels` at the end of each segment. Only the dividers of the
+ * `resizable` columns take a drag.
*/
- setColumns(edges: readonly number[], labels: readonly string[]) {
+ setColumns(edges: readonly number[], labels: readonly string[], resizable: IndexRange) {
if (this.strip.childElementCount !== labels.length * 2) {
this.strip.replaceChildren();
for (const column of labels.keys()) {
- const segment = createElement("ck-table-column-bar__segment");
+ const segment = createElement(SEGMENT_CLASS);
const divider = createElement(DIVIDER_CLASS);
segment.dataset.column = String(column);
divider.dataset.column = String(column);
@@ -108,6 +115,8 @@ export default class TableColumnBarView extends View<HTMLDivElement> {
segment.style.width = `${Math.abs(end - start)}px`;
divider.style.left = `${end}px`;
divider.setAttribute("aria-label", label);
+ const isResizable = column >= resizable.first && column <= resizable.last;
+ divider.classList.toggle(RESIZABLE_DIVIDER_CLASS, isResizable);
}
}
diff --git a/packages/ckeditor5/src/plugins/table_distribute_columns.ts b/packages/ckeditor5/src/plugins/table_distribute_columns.ts
index 70f44aecd6..31132c2ba7 100644
--- a/packages/ckeditor5/src/plugins/table_distribute_columns.ts
+++ b/packages/ckeditor5/src/plugins/table_distribute_columns.ts
@@ -75,10 +75,14 @@ export function distributeColumns(editor: Editor, table: ModelElement, columns:
}
/**
- * The columns covered by `cells`, including every column a merged cell spans.
- * `TableUtils.getColumnIndexes()` only reports the column each cell starts in.
+ * The columns covered by `cells`, including every column a merged cell spans, or an empty range
+ * (`first > last`) when no cell of `table` is among them. `TableUtils.getColumnIndexes()` only
+ * reports the column each cell starts in.
*/
-function getSpannedColumns(table: ModelElement, cells: readonly ModelElement[]): IndexRange {
+export function getSpannedColumns(
+ table: ModelElement,
+ cells: readonly ModelElement[]
+): IndexRange {
const selected = new Set(cells);
let first = Infinity;
let last = -1;
diff --git a/packages/ckeditor5/src/plugins/viewport_geometry.ts b/packages/ckeditor5/src/plugins/viewport_geometry.ts
index ac677a58db..61d898fa82 100644
--- a/packages/ckeditor5/src/plugins/viewport_geometry.ts
+++ b/packages/ckeditor5/src/plugins/viewport_geometry.ts
@@ -1,4 +1,7 @@
-/** The distance from an edge of a visible area that scrolls it, in pixels. */
+/**
+ * The distance from an edge of a visible area that scrolls it, in pixels. Less than
+ * `--ck-table-column-bar-end-gap`, so the last divider of a scrolled table rests outside it.
+ */
const AUTO_SCROLL_EDGE = 40;
/** The largest distance scrolled per frame, in pixels. */
const AUTO_SCROLL_STEP = 16;
diff --git a/packages/ckeditor5/src/theme/table_column_bar.css b/packages/ckeditor5/src/theme/table_column_bar.css
index 028bc63ba2..110dd1ec6c 100644
--- a/packages/ckeditor5/src/theme/table_column_bar.css
+++ b/packages/ckeditor5/src/theme/table_column_bar.css
@@ -4,10 +4,18 @@
--ck-table-column-bar-segment-color:
var(--accented-background-color, var(--ck-color-base-hover));
--ck-table-column-bar-divider-color: var(--main-border-color, var(--ck-color-base-border));
+ --ck-table-column-bar-handle-color: var(--muted-text-color, var(--ck-color-text));
--ck-table-column-bar-active-color: var(--ck-color-focus-border);
--ck-table-column-bar-height: 28px;
--ck-table-column-bar-divider-hit-width: 24px;
+ --ck-table-column-bar-handle-width: 6px;
+ /* Must exceed `AUTO_SCROLL_EDGE` in viewport_geometry.ts. */
+ --ck-table-column-bar-end-gap: 64px;
+}
+
+.ck.ck-editor__editable.ck-table-column-bar-touch figure.table.ck-table-overflowing > table {
+ margin-inline-end: var(--ck-table-column-bar-end-gap);
}
/* Outranks the `.ck-reset_all` rules of the body collection. */
@@ -43,8 +51,10 @@
.ck-table-column-bar__divider {
position: absolute;
inset-block: 0;
+ z-index: 1;
width: var(--ck-table-column-bar-divider-hit-width);
translate: -50%;
+ pointer-events: none;
&::after {
position: absolute;
@@ -56,6 +66,17 @@
translate: -50%;
}
+ &.ck-table-column-bar__divider_resizable {
+ pointer-events: auto;
+
+ &::after {
+ inset-block: 4px;
+ border-radius: calc(var(--ck-table-column-bar-handle-width) / 2);
+ width: var(--ck-table-column-bar-handle-width);
+ background: var(--ck-table-column-bar-handle-color);
+ }
+ }
+
&.ck-table-column-bar__divider_active::after {
background: var(--ck-table-column-bar-active-color);
}