Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:sparkles: Show mobile table handles only for the focused row and column https://github.com/siyuan-note/siyuan/issues/20635

Daniel9b8f5fdd8b6d
diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-6yi0dv5/20200924101225-k254i8g.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-6yi0dv5/20200924101225-k254i8g.sy
index 9869dfa21c..41b9691d55 100644
--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-6yi0dv5/20200924101225-k254i8g.sy
+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-6yi0dv5/20200924101225-k254i8g.sy
@@ -6,7 +6,7 @@
"id": "20200924101225-k254i8g",
"title": "Content Block Type",
"type": "doc",
- "updated": "20261017171205"
+ "updated": "20261017174053"
},
"Children": [
{
@@ -1474,7 +1474,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20210104091538-a55chyw",
- "updated": "20261017171205"
+ "updated": "20261017174053"
},
"Children": [
{
@@ -1746,7 +1746,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20210104091538-38bsz5r",
- "updated": "20261017171205"
+ "updated": "20261017174053"
},
"Children": [
{
@@ -1957,12 +1957,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261017142635-d2uc99x",
- "updated": "20261017151154"
+ "updated": "20261017174053"
},
"Children": [
{
"Type": "NodeText",
- "Data": "Tap a handle above a column or beside a row to select that column or row. Enable Multi-select in the top toolbar to add or remove nonadjacent cells, rows, or columns. Use More to merge cells, set styles and alignment, or operate on selected rows and columns. Tap Close to leave selection mode."
+ "Data": "Tapping a cell shows blue dotted handles on the borders of its row and column. Tap a handle above a column or beside a row to select that column or row. Enable Multi-select in the top toolbar to add or remove nonadjacent cells, rows, or columns. Use More to merge cells, set styles and alignment, or operate on selected rows and columns. Tap Close to leave selection mode."
}
]
},
diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-fqgskfj/20200905090211-2vixtlf.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-fqgskfj/20200905090211-2vixtlf.sy
index be57dce794..bdb113e48a 100644
--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-fqgskfj/20200905090211-2vixtlf.sy
+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-fqgskfj/20200905090211-2vixtlf.sy
@@ -6,7 +6,7 @@
"id": "20200905090211-2vixtlf",
"title": "内容块类型",
"type": "doc",
- "updated": "20261017171205"
+ "updated": "20261017174053"
},
"Children": [
{
@@ -1507,7 +1507,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20210104090624-9qgquxh",
- "updated": "20261017171205"
+ "updated": "20261017174053"
},
"Children": [
{
@@ -1782,7 +1782,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20210104090624-erf17it",
- "updated": "20261017171205"
+ "updated": "20261017174053"
},
"Children": [
{
@@ -1997,12 +1997,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261017142635-bcg68ni",
- "updated": "20261017151154"
+ "updated": "20261017174053"
},
"Children": [
{
"Type": "NodeText",
- "Data": "点击列上方或行左侧的手柄可选中整列或整行。在顶部工具栏开启「多选」后,可点选增减不连续的单元格、行或列。通过「更多」可合并单元格、设置样式和对齐,或批量操作所选行列;点击「关闭」退出选择。"
+ "Data": "点击单元格后,其所在行和列的边框上会显示蓝色点阵手柄。点击列上方或行左侧的手柄可选中整列或整行。在顶部工具栏开启「多选」后,可点选增减不连续的单元格、行或列。通过「更多」可合并单元格、设置样式和对齐,或批量操作所选行列;点击「关闭」退出选择。"
}
]
},
diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226115825-mhcslw2/20211226120147-ib6yy3i.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226115825-mhcslw2/20211226120147-ib6yy3i.sy
index 0533ca9810..e845791f1d 100644
--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226115825-mhcslw2/20211226120147-ib6yy3i.sy
+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226115825-mhcslw2/20211226120147-ib6yy3i.sy
@@ -6,7 +6,7 @@
"id": "20211226120147-ib6yy3i",
"title": "內容區塊類型",
"type": "doc",
- "updated": "20261017171205"
+ "updated": "20261017174053"
},
"Children": [
{
@@ -1503,7 +1503,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20211226120227-esm6f20",
- "updated": "20261017171205"
+ "updated": "20261017174053"
},
"Children": [
{
@@ -1767,7 +1767,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20211226120227-fe8klj7",
- "updated": "20261017171205"
+ "updated": "20261017174053"
},
"Children": [
{
@@ -1984,12 +1984,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261017142635-qpn3xky",
- "updated": "20261017151154"
+ "updated": "20261017174053"
},
"Children": [
{
"Type": "NodeText",
- "Data": "點選欄上方或列左側的控點可選取整欄或整列。在頂部工具列開啟「多選」後,可點選增減不連續的儲存格、列或欄。透過「更多」可合併儲存格、設定樣式和對齊,或批次操作所選列欄;點選「關閉」退出選取。"
+ "Data": "點選儲存格後,其所在列和欄的邊框上會顯示藍色點陣控點。點選欄上方或列左側的控點可選取整欄或整列。在頂部工具列開啟「多選」後,可點選增減不連續的儲存格、列或欄。透過「更多」可合併儲存格、設定樣式和對齊,或批次操作所選列欄;點選「關閉」退出選取。"
}
]
},
diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-gvtksyj/20240530101000-35bbvcx.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-gvtksyj/20240530101000-35bbvcx.sy
index 03d643ee21..dda36dee6f 100644
--- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-gvtksyj/20240530101000-35bbvcx.sy
+++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-gvtksyj/20240530101000-35bbvcx.sy
@@ -7,7 +7,7 @@
"id": "20240530101000-35bbvcx",
"title": "コンテンツブロックの種類",
"type": "doc",
- "updated": "20261017171205"
+ "updated": "20261017174053"
},
"Children": [
{
@@ -1564,7 +1564,7 @@
"Properties": {
"ID": "20240530101000-rjjxxn8",
"id": "20240530101000-p035stn",
- "updated": "20261017171205"
+ "updated": "20261017174053"
},
"Children": [
{
@@ -1788,7 +1788,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20240530101000-riwihza",
- "updated": "20261017171205"
+ "updated": "20261017174053"
},
"Children": [
{
@@ -2015,12 +2015,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261017142635-udb0p1z",
- "updated": "20261017151154"
+ "updated": "20261017174053"
},
"Children": [
{
"Type": "NodeText",
- "Data": "列の上または行の左にあるハンドルをタップすると、列全体または行全体を選択できます。上部ツールバーで複数選択を有効にすると、離れたセル、行、列をタップして選択に追加したり、選択から外したりできます。「詳細」からセルの結合、スタイルや配置の設定、選択した行や列の一括操作を行えます。「閉じる」をタップすると選択を終了します。"
+ "Data": "セルをタップすると、その行と列の枠線上に青いドットのハンドルが表示されます。列の上または行の左にあるハンドルをタップすると、列全体または行全体を選択できます。上部ツールバーで複数選択を有効にすると、離れたセル、行、列をタップして選択に追加したり、選択から外したりできます。「詳細」からセルの結合、スタイルや配置の設定、選択した行や列の一括操作を行えます。「閉じる」をタップすると選択を終了します。"
}
]
},
diff --git a/app/src/assets/scss/protyle/_protyle.scss b/app/src/assets/scss/protyle/_protyle.scss
index 1e45e4c119..72e40defba 100644
--- a/app/src/assets/scss/protyle/_protyle.scss
+++ b/app/src/assets/scss/protyle/_protyle.scss
@@ -1531,10 +1531,6 @@ table + .protyle-action__table {
&.protyle-table-control__handle--column::after {
top: -12px;
}
-
- &:not(:hover):not(.protyle-table-control__handle--active)::before {
- opacity: 1;
- }
}
}
.image-ocr {
diff --git a/app/src/protyle/util/tableControl.ts b/app/src/protyle/util/tableControl.ts
index f3707bec95..47db9b02ef 100644
--- a/app/src/protyle/util/tableControl.ts
+++ b/app/src/protyle/util/tableControl.ts
@@ -567,6 +567,13 @@ export class TableControl {
return;
}
const table = cell.closest("table");
+ const grid = this.selectionGrid || this.gridCache.get(table).grid;
+ const info = grid.cellInfos.find(item => item.cell === cell);
+ const row = info && table.rows[info.row]?.getBoundingClientRect();
+ const column = info && this.getColumnRect(table, grid, info.col);
+ if (!row || !column) {
+ return;
+ }
const viewport = this.getTableGridViewportRect(table);
const visualViewport = window.visualViewport;
viewport.left = Math.max(viewport.left, visualViewport?.offsetLeft || 0);
@@ -574,7 +581,9 @@ export class TableControl {
viewport.top = Math.max(viewport.top, visualViewport?.offsetTop || 0);
viewport.bottom = Math.min(viewport.bottom, (visualViewport?.height || window.innerHeight) +
(visualViewport?.offsetTop || 0), window.innerHeight);
- return {cell, table, viewport, grid: this.selectionGrid || this.gridCache.get(table).grid,
+ return {cell, table, viewport, grid,
+ row: {index: info.row, top: row.top, bottom: row.bottom},
+ column: {index: info.col, left: column.left, right: column.right},
selection: this.selection ? {
mode: this.selection.mode,
cells: this.getSelectedCells(),
diff --git a/app/src/protyle/util/tableTouch.test.ts b/app/src/protyle/util/tableTouch.test.ts
index b15099c884..5f1a80a13b 100644
--- a/app/src/protyle/util/tableTouch.test.ts
+++ b/app/src/protyle/util/tableTouch.test.ts
@@ -194,6 +194,72 @@ const browserCases = async (sources: Record<string, string>) => {
check.equal(f.touch("[data-action='width']"), null, "an editing caret does not expose a ruler button");
f.dispose();
}
+ {
+ const f = fixture();
+ const focus = (cell: HTMLTableCellElement) => {
+ const range = document.createRange();
+ range.selectNodeContents(cell);
+ range.collapse(true);
+ focusByRange(range);
+ document.dispatchEvent(new Event("selectionchange"));
+ f.render();
+ };
+ for (const [row, col] of [[1, 1], [2, 2]]) {
+ const cell = f.cell(row, col);
+ focus(cell);
+ const handles = f.root.querySelectorAll(".protyle-table-control__touch-handle");
+ check.equal(handles.length, 2, "only the focused row and column expose handles");
+ handles.forEach(handle => {
+ check.equal(handle.classList.contains("protyle-table-control__handle--active"), true,
+ "focused handles always use the shared blue dotted style");
+ check.equal(handle.getAttribute("aria-pressed"), "false", "focus does not imply a row or column selection");
+ });
+ const rect = cell.getBoundingClientRect();
+ const rowHandle = f.touch("[data-mode='row']").getBoundingClientRect();
+ const columnHandle = f.touch("[data-mode='column']").getBoundingClientRect();
+ check.equal(rowHandle.top + rowHandle.height / 2, rect.top + rect.height / 2);
+ check.equal(columnHandle.left + columnHandle.width / 2, rect.left + rect.width / 2);
+ }
+ for (const mode of ["row", "column"] as const) {
+ f.core.clear();
+ const cell = f.cell(2, 2);
+ focus(cell);
+ const handle = f.touch(`[data-mode='${mode}']`);
+ const rect = handle.getBoundingClientRect();
+ pointer(handle, "pointerdown", rect.left + rect.width / 2, rect.top + rect.height / 2);
+ pointer(document, "pointerup", rect.left + rect.width / 2, rect.top + rect.height / 2);
+ f.render();
+ check.equal(f.invoke("getTouchState").cell, cell, "selecting an axis preserves the focused cell on the other axis");
+ check.equal(f.touch(`[data-mode='${mode}']`).getAttribute("aria-pressed"), "true");
+ }
+ f.dispose();
+ }
+ {
+ const f = fixture();
+ const merged = f.cell(1, 1);
+ merged.colSpan = 2;
+ f.cell(1, 2).remove();
+ merged.rowSpan = 2;
+ f.cell(2, 2).remove();
+ f.cell(2, 1).remove();
+ f.core.startTouchSelection(merged);
+ f.render();
+ const state = f.invoke("getTouchState");
+ const row = f.table.rows[1].getBoundingClientRect();
+ const col = f.table.querySelectorAll("col")[1].getBoundingClientRect();
+ check.deepEqual(state.row, {index: 1, top: row.top, bottom: row.bottom});
+ check.deepEqual(state.column, {index: 1, left: col.left, right: col.right},
+ "merged cells use logical row and column geometry shared with desktop");
+ f.table.style.minWidth = "270px";
+ f.table.parentElement.style.width = "90px";
+ f.render();
+ check.equal(f.touch("[data-mode='column']"), null, "an offscreen focused column has no misplaced handle");
+ check.notEqual(f.touch("[data-mode='row']"), null, "the visible focused row retains its handle");
+ f.table.parentElement.scrollLeft = 150;
+ f.render();
+ check.notEqual(f.touch("[data-mode='column']"), null, "scrolling the focused column into view restores its handle");
+ f.dispose();
+ }
for (const kind of ["tap", "move", "cancel", "scroll", "multiple", "blur", "disabled", "block", "removed"]) {
const f = fixture();
const cell = f.cell(1, 0);
@@ -278,10 +344,11 @@ const browserCases = async (sources: Record<string, string>) => {
check.equal(f.root.scrollTop, 0, "dragging near a fully visible table edge does not scroll the document");
f.root.scrollTop = 20;
await frames(4);
- const header = f.cell(0, 0).getBoundingClientRect();
+ const focusedRow = f.cell(3, 1).parentElement.getBoundingClientRect();
const column = f.touch("[data-mode='column']").getBoundingClientRect();
const row = f.touch("[data-mode='row']").getBoundingClientRect();
- check.equal(row.top + row.height / 2, (Math.max(header.top, column.top + column.height / 2) + header.bottom) / 2,
+ check.equal(row.top + row.height / 2,
+ (Math.max(focusedRow.top, column.top + column.height / 2) + focusedRow.bottom) / 2,
"row handles follow scrolling while an endpoint is being dragged");
pointer(document, "pointercancel");
f.dispose();
diff --git a/app/src/protyle/util/tableTouch.ts b/app/src/protyle/util/tableTouch.ts
index 7aafce40e3..f28436e190 100644
--- a/app/src/protyle/util/tableTouch.ts
+++ b/app/src/protyle/util/tableTouch.ts
@@ -13,6 +13,8 @@ export interface ITableTouchState {
cell: HTMLTableCellElement;
table: HTMLTableElement;
grid: ITableGrid;
+ row: {index: number, top: number, bottom: number};
+ column: {index: number, left: number, right: number};
viewport: {left: number, top: number, right: number, bottom: number};
selection?: {
mode: SelectionMode;
@@ -212,41 +214,27 @@ export class TableTouchControl {
if (!state || state.viewport.right <= state.viewport.left || state.viewport.bottom <= state.viewport.top) {
return;
}
- const {viewport, grid, cell, table, selection} = state;
- const visibleInfos = grid.cellInfos.filter(info => info.cell.isConnected &&
- !info.cell.classList.contains("fn__none"));
- const rows = new Set<number>();
- const columns = new Set<number>();
- visibleInfos.forEach(info => {
- const rect = info.cell.getBoundingClientRect();
- if (rect.bottom <= viewport.top || rect.top >= viewport.bottom ||
- rect.right <= viewport.left || rect.left >= viewport.right) {
- return;
- }
- if (!rows.has(info.row)) {
- rows.add(info.row);
- const row = this.button(window.siyuan.languages.row, "iconDrag", viewport.left,
- (Math.max(rect.top, viewport.top) + Math.min(rect.bottom, viewport.bottom)) / 2, false);
- row.className = "protyle-table-control__handle protyle-table-control__handle--row protyle-table-control__touch-handle";
- row.style.height = `${Math.min(rect.bottom, viewport.bottom) - Math.max(rect.top, viewport.top)}px`;
- row.dataset.mode = "row";
- row.setAttribute("aria-pressed", String(selection?.mode === "row" && selection.indexes.has(info.row)));
- row.classList.toggle("protyle-table-control__handle--active", selection?.mode === "row" && selection.indexes.has(info.row));
- row.addEventListener("pointerdown", event => this.selectHandle(event, info.cell, "row", row));
- }
- // 列控件只按逻辑列创建一次,支持没有表头的表格。
- if (!columns.has(info.col)) {
- columns.add(info.col);
- const column = this.button(window.siyuan.languages.column, "iconDrag",
- (Math.max(rect.left, viewport.left) + Math.min(rect.right, viewport.right)) / 2, viewport.top, false);
- column.className = "protyle-table-control__handle protyle-table-control__handle--column protyle-table-control__touch-handle";
- column.style.width = `${Math.min(rect.right, viewport.right) - Math.max(rect.left, viewport.left)}px`;
- column.dataset.mode = "column";
- column.setAttribute("aria-pressed", String(selection?.mode === "column" && selection.indexes.has(info.col)));
- column.classList.toggle("protyle-table-control__handle--active", selection?.mode === "column" && selection.indexes.has(info.col));
- column.addEventListener("pointerdown", event => this.selectHandle(event, info.cell, "column", column));
- }
- });
+ const {viewport, cell, table, selection} = state;
+ const rowRect = state.row;
+ if (rowRect.bottom > viewport.top && rowRect.top < viewport.bottom) {
+ const row = this.button(window.siyuan.languages.row, "iconDrag", viewport.left,
+ (Math.max(rowRect.top, viewport.top) + Math.min(rowRect.bottom, viewport.bottom)) / 2, false);
+ row.className = "protyle-table-control__handle protyle-table-control__handle--row protyle-table-control__handle--active protyle-table-control__touch-handle";
+ row.style.height = `${Math.min(rowRect.bottom, viewport.bottom) - Math.max(rowRect.top, viewport.top)}px`;
+ row.dataset.mode = "row";
+ row.setAttribute("aria-pressed", String(selection?.mode === "row" && selection.indexes.has(rowRect.index)));
+ row.addEventListener("pointerdown", event => this.selectHandle(event, cell, "row", row));
+ }
+ const columnRect = state.column;
+ if (columnRect.right > viewport.left && columnRect.left < viewport.right) {
+ const column = this.button(window.siyuan.languages.column, "iconDrag",
+ (Math.max(columnRect.left, viewport.left) + Math.min(columnRect.right, viewport.right)) / 2, viewport.top, false);
+ column.className = "protyle-table-control__handle protyle-table-control__handle--column protyle-table-control__handle--active protyle-table-control__touch-handle";
+ column.style.width = `${Math.min(columnRect.right, viewport.right) - Math.max(columnRect.left, viewport.left)}px`;
+ column.dataset.mode = "column";
+ column.setAttribute("aria-pressed", String(selection?.mode === "column" && selection.indexes.has(columnRect.index)));
+ column.addEventListener("pointerdown", event => this.selectHandle(event, cell, "column", column));
+ }
this.renderColumnBoundary(state);
const tableRect = table.getBoundingClientRect();
const addOffset = TABLE_ADD_CONTROL_GAP + TABLE_ADD_CONTROL_THICKNESS / 2;