Skip to content

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

:lipstick: Place mobile table handles on grid borders https://github.com/siyuan-note/siyuan/issues/20635

Danieledc5ebf7428d
diff --git a/app/src/assets/scss/protyle/_protyle.scss b/app/src/assets/scss/protyle/_protyle.scss
index 69273413d7..ce54a95e68 100644
--- a/app/src/assets/scss/protyle/_protyle.scss
+++ b/app/src/assets/scss/protyle/_protyle.scss
@@ -1491,10 +1491,24 @@ html[data-frontend="browser-mobile"] .protyle-wysiwyg [data-type="NodeTable"] >
}
&__touch-handle {
- width: 28px;
- height: 28px;
+ width: 16px;
+ height: 16px;
touch-action: none;
+ &::after {
+ content: "";
+ position: absolute;
+ inset: 0;
+ }
+
+ &.protyle-table-control__handle--row::after {
+ left: -12px;
+ }
+
+ &.protyle-table-control__handle--column::after {
+ top: -12px;
+ }
+
&:not(:hover):not(.protyle-table-control__handle--active)::before {
opacity: 1;
}
diff --git a/app/src/protyle/util/tableTouch.test.ts b/app/src/protyle/util/tableTouch.test.ts
index 618e5ff3bc..4f9719413e 100644
--- a/app/src/protyle/util/tableTouch.test.ts
+++ b/app/src/protyle/util/tableTouch.test.ts
@@ -274,6 +274,33 @@ const browserCases = async (sources: Record<string, string>) => {
check.equal(f.table.rows.length, 3, "shrinking preserves all nonempty rows");
f.dispose();
}
+ {
+ const f = fixture();
+ f.root.style.height = `${window.innerHeight}px`;
+ f.table.style.margin = "100px 0 0";
+ f.table.parentElement.style.width = "180px";
+ f.table.parentElement.scrollLeft = 45;
+ f.core.startTouchSelection(f.cell(0, 0));
+ f.render();
+ const cellRect = f.cell(0, 0).getBoundingClientRect();
+ const wrapperRect = f.table.parentElement.getBoundingClientRect();
+ const row = f.touch("[data-mode='row']").getBoundingClientRect();
+ const column = f.touch("[data-mode='column']").getBoundingClientRect();
+ check.equal(row.left + row.width / 2, wrapperRect.left, "row handles follow the clipped grid border at the screen edge");
+ check.equal(column.top + column.height / 2, cellRect.top, "column handles sit on the top grid border");
+ check.equal(column.left + column.width / 2, (wrapperRect.left + cellRect.right) / 2,
+ "column handles stay centered on the visible portion when horizontally scrolled");
+ f.table.style.marginTop = `${window.innerHeight - 70}px`;
+ f.render();
+ const bottomCell = f.cell(0, 0).getBoundingClientRect();
+ const bottomRow = f.touch("[data-mode='row']").getBoundingClientRect();
+ const bottomColumn = f.touch("[data-mode='column']").getBoundingClientRect();
+ check.equal(bottomRow.top + bottomRow.height / 2, bottomCell.top + bottomCell.height / 2,
+ "row handles remain aligned near the bottom of the viewport");
+ check.equal(bottomColumn.top + bottomColumn.height / 2, bottomCell.top,
+ "column handles remain on the grid border near the bottom of the viewport");
+ f.dispose();
+ }
for (const mode of ["row", "column"] as const) {
const f = fixture();
f.core.startTouchSelection(f.cell(1, 0), mode);
diff --git a/app/src/protyle/util/tableTouch.ts b/app/src/protyle/util/tableTouch.ts
index eeac69c65b..572a4ccf75 100644
--- a/app/src/protyle/util/tableTouch.ts
+++ b/app/src/protyle/util/tableTouch.ts
@@ -159,8 +159,8 @@ export class TableTouchControl {
}
if (!rows.has(info.row)) {
rows.add(info.row);
- const row = this.button(window.siyuan.languages.row, "iconDrag", viewport.left - 14,
- (Math.max(rect.top, viewport.top) + Math.min(rect.bottom, viewport.bottom)) / 2);
+ 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";
@@ -172,7 +172,7 @@ export class TableTouchControl {
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 - 14);
+ (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";
@@ -247,14 +247,14 @@ export class TableTouchControl {
}
}
- private button(label: string, icon: string, left: number, top: number) {
+ private button(label: string, icon: string, left: number, top: number, clampToScreen = true) {
const button = document.createElement("button");
button.type = "button";
button.className = "block__icon block__icon--show protyle-table-control__touch-button";
button.setAttribute("aria-label", label);
button.innerHTML = `<svg><use xlink:href="#${icon}"></use></svg>`;
- button.style.left = `${Math.max(16, Math.min(window.innerWidth - 16, left))}px`;
- button.style.top = `${Math.max(16, Math.min(window.innerHeight - 72, top))}px`;
+ button.style.left = `${clampToScreen ? Math.max(16, Math.min(window.innerWidth - 16, left)) : left}px`;
+ button.style.top = `${clampToScreen ? Math.max(16, Math.min(window.innerHeight - 72, top)) : top}px`;
this.controls.append(button);
return button;
}