An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:sparkles: Improve mobile table selection and column resizing https://github.com/siyuan-note/siyuan/issues/20635
Daniel9377b6ed3da8
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.syindex 8d9be62143..1c59ad05c7 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": "20261017151154"+ "updated": "20261017170001"},"Children": [{@@ -1474,7 +1474,7 @@"HeadingLevel": 2,"Properties": {"id": "20210104091538-a55chyw",- "updated": "20261017151154"+ "updated": "20261017170001"},"Children": [{@@ -1746,7 +1746,7 @@"HeadingLevel": 3,"Properties": {"id": "20210104091538-38bsz5r",- "updated": "20261017151154"+ "updated": "20261017170001"},"Children": [{@@ -1943,12 +1943,12 @@"Type": "NodeParagraph","Properties": {"id": "20261017142635-7s38p0k",- "updated": "20261017142635"+ "updated": "20261017170001"},"Children": [{"Type": "NodeText",- "Data": "On mobile, tap a cell to edit its text. Use the selection button beside the cell or the block menu in the keyboard toolbar to select a cell range. Drag either corner handle to expand or shrink the selection; dragging near the viewport edge scrolls the table. Swiping cell content still scrolls, and holding text still selects text."+ "Data": "On mobile, tap a cell to edit its text. Long-press a cell that is not being edited to select a cell range, or use the block menu in the keyboard toolbar. Drag either corner handle to expand or shrink the selection; dragging near the viewport edge scrolls the table. Swiping cell content still scrolls. While editing text, holding text still selects text."}]},@@ -1971,12 +1971,12 @@"Type": "NodeParagraph","Properties": {"id": "20261017142635-wrzqg7l",- "updated": "20261017142635"+ "updated": "20261017170001"},"Children": [{"Type": "NodeText",- "Data": "Drag the column-width handle to change a column's width. Select columns and use More to auto-fit their widths or distribute them evenly. Tap the plus controls at the table edges to add rows or columns, or drag the edge controls to add several at once or remove trailing empty rows and columns. Shrinking preserves nonempty content and merged cells."+ "Data": "Tap a column divider in the top row to highlight it, then drag its top-row segment to change the width. Tap elsewhere to leave width adjustment. Select columns and use More to auto-fit their widths or distribute them evenly. Tap the plus controls at the table edges to add rows or columns, or drag the edge controls to add several at once or remove trailing empty rows and columns. Shrinking preserves nonempty content and merged cells."}]},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.syindex ca09143c26..1d15f5187e 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": "20261017151154"+ "updated": "20261017170001"},"Children": [{@@ -1507,7 +1507,7 @@"HeadingLevel": 2,"Properties": {"id": "20210104090624-9qgquxh",- "updated": "20261017151154"+ "updated": "20261017170001"},"Children": [{@@ -1782,7 +1782,7 @@"HeadingLevel": 3,"Properties": {"id": "20210104090624-erf17it",- "updated": "20261017151154"+ "updated": "20261017170001"},"Children": [{@@ -1983,12 +1983,12 @@"Type": "NodeParagraph","Properties": {"id": "20261017142635-4dbby6c",- "updated": "20261017142635"+ "updated": "20261017170001"},"Children": [{"Type": "NodeText",- "Data": "移动端点击单元格可编辑文字,通过单元格旁的选择按钮或键盘工具栏的块菜单进入区域选择。拖动选区的两个角点手柄可扩大或缩小范围,拖到视口边缘可自动滚动表格。滑动单元格内容仍用于滚动,长按文字仍用于选字。"+ "Data": "移动端点击单元格可编辑文字。长按尚未进入编辑的单元格可进入区域选择,也可使用键盘工具栏的块菜单。拖动选区的两个角点手柄可扩大或缩小范围,拖到视口边缘可自动滚动表格。滑动单元格内容仍用于滚动;编辑文字时,长按仍用于选字。"}]},@@ -2011,12 +2011,12 @@"Type": "NodeParagraph","Properties": {"id": "20261017142635-oe1mo6v",- "updated": "20261017142635"+ "updated": "20261017170001"},"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.syindex 6091431929..1154943ad2 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": "20261017151154"+ "updated": "20261017170001"},"Children": [{@@ -1503,7 +1503,7 @@"HeadingLevel": 2,"Properties": {"id": "20211226120227-esm6f20",- "updated": "20261017151154"+ "updated": "20261017170001"},"Children": [{@@ -1767,7 +1767,7 @@"HeadingLevel": 3,"Properties": {"id": "20211226120227-fe8klj7",- "updated": "20261017151154"+ "updated": "20261017170001"},"Children": [{@@ -1970,12 +1970,12 @@"Type": "NodeParagraph","Properties": {"id": "20261017142635-6swexeg",- "updated": "20261017142635"+ "updated": "20261017170001"},"Children": [{"Type": "NodeText",- "Data": "行動端點選儲存格可編輯文字,透過儲存格旁的選取按鈕或鍵盤工具列的區塊選單進入區域選取。拖曳選取範圍的兩個角點控點可擴大或縮小範圍,拖到可視區域邊緣可自動捲動表格。滑動儲存格內容仍用於捲動,長按文字仍用於選字。"+ "Data": "行動端點選儲存格可編輯文字。長按尚未進入編輯的儲存格可進入區域選取,也可使用鍵盤工具列的區塊選單。拖曳選取範圍的兩個角點控點可擴大或縮小範圍,拖到可視區域邊緣可自動捲動表格。滑動儲存格內容仍用於捲動;編輯文字時,長按仍用於選字。"}]},@@ -1998,12 +1998,12 @@"Type": "NodeParagraph","Properties": {"id": "20261017142635-5ds55er",- "updated": "20261017142635"+ "updated": "20261017170001"},"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.syindex c9b4b742ca..e3ec214f8b 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": "20261017151154"+ "updated": "20261017170001"},"Children": [{@@ -1564,7 +1564,7 @@"Properties": {"ID": "20240530101000-rjjxxn8","id": "20240530101000-p035stn",- "updated": "20261017151154"+ "updated": "20261017170001"},"Children": [{@@ -1788,7 +1788,7 @@"HeadingLevel": 3,"Properties": {"id": "20240530101000-riwihza",- "updated": "20261017151154"+ "updated": "20261017170001"},"Children": [{@@ -2001,12 +2001,12 @@"Type": "NodeParagraph","Properties": {"id": "20261017142635-kll3m6b",- "updated": "20261017142635"+ "updated": "20261017170001"},"Children": [{"Type": "NodeText",- "Data": "モバイル端末ではセルをタップして文字を編集できます。セルの横にある選択ボタン、またはキーボードツールバーのブロックメニューからセル範囲の選択に入ります。選択範囲の両端のハンドルをドラッグして範囲を変更でき、画面の端までドラッグすると表が自動的にスクロールします。セル内をスワイプするとスクロールし、文字を長押しすると文字を選択できます。"+ "Data": "モバイル端末ではセルをタップして文字を編集できます。編集中ではないセルを長押しするか、キーボードツールバーのブロックメニューを使うと、セル範囲の選択に入ります。選択範囲の両端のハンドルをドラッグして範囲を変更でき、画面の端までドラッグすると表が自動的にスクロールします。セル内をスワイプするとスクロールします。文字の編集中は、長押しで文字を選択できます。"}]},@@ -2029,12 +2029,12 @@"Type": "NodeParagraph","Properties": {"id": "20261017142635-99sm3ym",- "updated": "20261017142635"+ "updated": "20261017170001"},"Children": [{"Type": "NodeText",- "Data": "列幅のハンドルをドラッグすると列幅を変更できます。列を選択して「詳細」を開くと、内容に合わせて列幅を自動調整したり、均等に配分したりできます。表の端のプラスボタンをタップすると行や列を追加できます。端のコントロールをドラッグすると複数の行や列を追加したり、末尾の空の行や列を削除したりできます。表を縮めても、内容のあるセルや結合セルは保持されます。"+ "Data": "表の先頭行にある列の区切り線をタップすると強調表示されます。その先頭行の線をドラッグして列幅を変更し、他の場所をタップすると調整を終了します。列を選択して「詳細」を開くと、内容に合わせて列幅を自動調整したり、均等に配分したりできます。表の端のプラスボタンをタップすると行や列を追加できます。端のコントロールをドラッグすると複数の行や列を追加したり、末尾の空の行や列を削除したりできます。表を縮めても、内容のあるセルや結合セルは保持されます。"}]},diff --git a/app/src/assets/scss/protyle/_protyle.scss b/app/src/assets/scss/protyle/_protyle.scssindex ce54a95e68..09db6f4bc4 100644--- a/app/src/assets/scss/protyle/_protyle.scss+++ b/app/src/assets/scss/protyle/_protyle.scss@@ -1246,9 +1246,10 @@ table + .protyle-action__table {}}-html[data-frontend="mobile"] .protyle-wysiwyg [data-type="NodeTable"] > div:first-child,-html[data-frontend="browser-mobile"] .protyle-wysiwyg [data-type="NodeTable"] > div:first-child {- padding-top: 16px;+.table__cell--touch-selecting {+ user-select: none;+ -webkit-user-select: none;+ -webkit-touch-callout: none;}.protyle-table-control {@@ -1433,13 +1434,35 @@ html[data-frontend="browser-mobile"] .protyle-wysiwyg [data-type="NodeTable"] >pointer-events: none;}- &__drop {+ &__drop,+ &__width-guide {position: fixed;z-index: 3;background-color: var(--b3-theme-primary);pointer-events: none;}+ &__width-guide {+ width: 2px;+ transform: translateX(-50%);+ }++ &__width {+ width: 28px;+ cursor: col-resize;+ touch-action: none;++ &::before {+ width: 2px;+ height: 100%;+ background-color: var(--b3-theme-primary);+ }++ &:hover::before {+ opacity: 1;+ }+ }+&--touch {> .protyle-table-control__handle,> .protyle-table-control__add {diff --git a/app/src/mobile/util/touch.ts b/app/src/mobile/util/touch.tsindex c86dee87d0..5bb03843c6 100644--- a/app/src/mobile/util/touch.ts+++ b/app/src/mobile/util/touch.ts@@ -459,6 +459,7 @@ export const handleTouchStart = (event: TouchEvent) => {target.dataset.type,!!hasClosestByAttribute(target, "data-type", "inline-math"),target.tagName === "IMG" && !!hasClosestByClassName(target, "img"),+ !!target.closest("td, th") && !!target.closest('[data-type="NodeTable"]'),)) {longPressBlockElement = blockElement;const touchRange = getRangeByPoint(event.touches[0].clientX, event.touches[0].clientY);diff --git a/app/src/mobile/util/touchGesture.test.ts b/app/src/mobile/util/touchGesture.test.tsindex ca6fda14b4..44bbfafcf5 100644--- a/app/src/mobile/util/touchGesture.test.ts+++ b/app/src/mobile/util/touchGesture.test.ts@@ -20,6 +20,8 @@ describe("mobile touch gesture", () => {assert.equal(shouldStartLongPressMultiSelect("SPAN", "strong a", false, false), false);assert.equal(shouldStartLongPressMultiSelect("PROTYLE-HTML", undefined, true, false), false);assert.equal(shouldStartLongPressMultiSelect("IMG", undefined, false, true), false);+ assert.equal(shouldStartLongPressMultiSelect("TD", undefined, false, false, true), false);+ assert.equal(shouldStartLongPressMultiSelect("SPAN", "strong", false, false, true), false);});it("starts multi-select for ordinary block content", () => {diff --git a/app/src/mobile/util/touchGesture.ts b/app/src/mobile/util/touchGesture.tsindex c15a7434a7..7cda8fd5f6 100644--- a/app/src/mobile/util/touchGesture.ts+++ b/app/src/mobile/util/touchGesture.ts@@ -12,6 +12,7 @@ export const shouldStartLongPressMultiSelect = (dataType: string | undefined,insideInlineMath: boolean,imageMenuTarget: boolean,+ insideTableCell = false,) => !(tagName === "SPAN" && (dataType || "").split(" ").some(type =>["block-ref", "file-annotation-ref", "tag", "inline-memo", "a"].includes(type))) &&- !insideInlineMath && !imageMenuTarget;+ !insideInlineMath && !imageMenuTarget && !insideTableCell;diff --git a/app/src/protyle/util/tableControl.ts b/app/src/protyle/util/tableControl.tsindex 08aa8efef4..4b2e0f086e 100644--- a/app/src/protyle/util/tableControl.ts+++ b/app/src/protyle/util/tableControl.ts@@ -407,6 +407,16 @@ export class TableControl {this.bindEvents();if (isMobile()) {this.touch = new TableTouchControl(wysiwygElement, this.element, () => protyle.contentElement || protyle.element, {+ enabled: () => !protyle.disabled && !protyle.toolbar.isMultiSelectMode(),+ activate: cell => {+ if (protyle.disabled || !finishTableCellEditing(cell)) {+ return false;+ }+ this.clear();+ this.caretCell = cell;+ this.blurTouchEditor();+ return true;+ },state: () => this.getTouchState(),select: (cell, mode, toggle, extend) => this.startTouchSelection(cell, mode, toggle, extend),range: (anchor, active) => this.selectCellRange(anchor, active),diff --git a/app/src/protyle/util/tableTouch.test.ts b/app/src/protyle/util/tableTouch.test.tsindex 4f9719413e..9a803275ab 100644--- a/app/src/protyle/util/tableTouch.test.ts+++ b/app/src/protyle/util/tableTouch.test.ts@@ -15,7 +15,8 @@ const browserCases = async (sources: Record<string, string>) => {fixtureStyle.textContent = ".protyle-util{position:fixed;top:8px;left:8px;right:8px}.block__icons{display:flex;height:42px}" +".block__icons svg,.protyle-table-control svg{width:16px;height:16px}.fn__none{display:none}" +".protyle-table-control__handle,.protyle-table-control__add,.protyle-table-control__touch-button{" +- "position:fixed;width:28px;height:28px;transform:translate(-50%,-50%)}";+ "position:fixed;width:28px;height:28px;transform:translate(-50%,-50%)}" ++ ".protyle-table-control__width-guide{position:fixed}";document.head.append(fixtureStyle);const transactions: {before: string, after: string}[] = [];const clipboard: {textPlain: string, textHTML?: string, textSiyuan?: string}[] = [];@@ -52,7 +53,8 @@ const browserCases = async (sources: Record<string, string>) => {range.collapse(true);return range;};- const constants = new Proxy<Record<string, string>>({ZWSP: "\u200b"}, {get: (target, key: string) => target[key] || key});+ const constants = new Proxy<Record<string, string | number>>({ZWSP: "\u200b", TIMEOUT_LONGPRESS: 20,+ SIZE_DRAG_THRESHOLD: 5}, {get: (target, key: string) => target[key] || key});const stubs: Record<string, object | (() => object)> = {"src/constants.ts": {Constants: constants},"src/menus/menuToggle.ts": {toggleMenu: (options: {build: (menu: object, session: object) => void}) => {@@ -130,6 +132,13 @@ const browserCases = async (sources: Record<string, string>) => {const tick = () => new Promise(resolve => setTimeout(resolve, 30));const pointer = (target: EventTarget, type: string, x = 0, y = 0, id = 1) => target.dispatchEvent(new PointerEvent(type,{bubbles: true, cancelable: true, clientX: x, clientY: y, button: 0, pointerId: id, pointerType: "touch"}));+ const touchEvent = (target: Element, type: string, x = 60, y = 110, count = 1) => {+ const points = Array.from({length: count}, (_, identifier) => new Touch({identifier, target, clientX: x, clientY: y}));+ const event = new TouchEvent(type, {bubbles: true, cancelable: true, changedTouches: points,+ touches: type === "touchend" || type === "touchcancel" ? [] : points});+ target.dispatchEvent(event);+ return event;+ };const fixture = () => {const root = document.createElement("div");const editor = document.createElement("div");@@ -143,7 +152,9 @@ const browserCases = async (sources: Record<string, string>) => {root.append(editor);document.body.append(root);editor.querySelectorAll<HTMLElement>("td, th").forEach(cell => cell.style.height = "42px");- const owner = {element: root, contentElement: root, disabled: false, toolbar: {}, options: {},+ let blockMultiSelect = false;+ const owner = {element: root, contentElement: root, disabled: false,+ toolbar: {isMultiSelectMode: () => blockMultiSelect}, options: {},wysiwyg: {element: editor}, lute: {}, block: {rootID: "root"}} as unknown as IProtyle;const core = new TableControl(owner, editor);owner.wysiwyg.tableControl = core;@@ -152,8 +163,62 @@ const browserCases = async (sources: Record<string, string>) => {const invoke = (name: string, ...args: unknown[]) => Reflect.get(core, name).apply(core, args);const touch = (selector: string) => root.querySelector<HTMLElement>(selector);const dispose = () => { core.destroy(); root.remove(); getSelection().removeAllRanges(); };- return {root, editor, owner, core, get table() { return editor.querySelector("table"); }, cell, render, invoke, touch, dispose};+ return {root, editor, owner, core, get table() { return editor.querySelector("table"); }, cell, render, invoke, touch, dispose,+ setBlockMultiSelect: (value: boolean) => { blockMultiSelect = value; }};};+ {+ const f = fixture();+ const cell = f.cell(1, 0);+ touchEvent(cell, "touchstart");+ await tick();+ check.equal(f.core.hasTouchSelection(), true, "holding an inactive cell enters cell selection");+ check.deepEqual(f.core.getSelectedCells(), [cell]);+ check.equal(touchEvent(cell, "touchend").defaultPrevented, true, "release consumes the long press instead of editing");+ check.equal(cell.classList.contains("table__cell--touch-selecting"), false);+ const menu = new MouseEvent("contextmenu", {bubbles: true, cancelable: true});+ cell.dispatchEvent(menu);+ check.equal(menu.defaultPrevented, true, "the same long press cannot open another context menu");+ f.core.clear();+ const range = document.createRange();+ range.selectNodeContents(cell);+ range.collapse(true);+ focusByRange(range);+ document.dispatchEvent(new Event("selectionchange"));+ f.render();+ check.equal(f.touch("[data-action='select']"), null, "cell selection no longer adds a checkmark button");+ check.equal(f.touch("[data-action='width']"), null, "an editing caret does not expose a ruler button");+ f.dispose();+ }+ for (const kind of ["tap", "move", "cancel", "scroll", "multiple", "blur", "disabled", "block", "removed"]) {+ const f = fixture();+ const cell = f.cell(1, 0);+ if (kind === "disabled") f.owner.disabled = true;+ if (kind === "block") f.setBlockMultiSelect(true);+ touchEvent(cell, "touchstart");+ if (kind === "tap") check.equal(touchEvent(cell, "touchend").defaultPrevented, false);+ if (kind === "move") check.equal(touchEvent(cell, "touchmove", 66, 110).defaultPrevented, false);+ if (kind === "cancel") touchEvent(cell, "touchcancel");+ if (kind === "scroll") f.root.dispatchEvent(new Event("scroll"));+ if (kind === "multiple") touchEvent(cell, "touchstart", 60, 110, 2);+ if (kind === "blur") window.dispatchEvent(new Event("blur"));+ if (kind === "removed") cell.parentElement.remove();+ await tick();+ check.equal(f.core.hasTouchSelection(), false, `${kind} leaves the table unselected`);+ check.equal(cell.classList.contains("table__cell--touch-selecting"), false, `${kind} clears temporary touch state`);+ f.dispose();+ }+ for (const kind of ["editing", "link"]) {+ const f = fixture();+ const cell = f.cell(1, 0);+ const target = document.createElement(kind === "editing" ? "div" : "a");+ if (kind === "editing") target.className = "table__cell-editor";+ cell.append(target);+ touchEvent(target, "touchstart");+ await tick();+ check.equal(f.core.hasTouchSelection(), false, `${kind} retains its own long-press behavior`);+ check.equal(touchEvent(target, "touchend").defaultPrevented, false);+ f.dispose();+ }{const f = fixture();check.equal(f.core.startTouchSelection(f.cell(1, 0)), true);@@ -237,9 +302,17 @@ const browserCases = async (sources: Record<string, string>) => {}{const f = fixture();- f.core.startTouchSelection(f.cell(1, 0));+ const header = f.cell(0, 0);+ const headerRect = header.getBoundingClientRect();+ check.equal(f.touch("[data-action='width']"), null, "column resizing has no persistent ruler button");+ header.dispatchEvent(new MouseEvent("click", {bubbles: true, cancelable: true,+ clientX: headerRect.right, clientY: headerRect.top + headerRect.height / 2}));f.render();const width = f.touch("[data-action='width']");+ check.ok(width, "tapping a header divider activates its width control");+ check.equal(f.core.hasTouchSelection(), false, "activating a divider does not select the column's cells");+ check.equal(width.querySelector("svg"), null);+ check.equal(width.getBoundingClientRect().left + width.getBoundingClientRect().width / 2, headerRect.right);const before = f.table.querySelector("col").getAttribute("style");const count = transactions.length;pointer(width, "pointerdown", 120, 60);@@ -250,10 +323,43 @@ const browserCases = async (sources: Record<string, string>) => {f.render();pointer(f.touch("[data-action='width']"), "pointerdown", 120, 60);pointer(document, "pointermove", 180, 60);+ check.equal(f.touch(".protyle-table-control__width-guide").getBoundingClientRect().left,+ f.table.querySelector("col").getBoundingClientRect().right, "the divider guide follows the resized boundary");pointer(document, "pointerup", 180, 60);check.equal((f.table.querySelector("col") as HTMLElement).style.width, "150px");check.equal(transactions.length, count + 1);check.match(transactions.at(-1).before, /width:90px/);+ pointer(f.cell(1, 1), "pointerdown", 180, 110);+ f.render();+ check.equal(f.touch("[data-action='width']"), null, "touching cell content dismisses the active divider");+ const bodyRect = f.cell(1, 0).getBoundingClientRect();+ f.cell(1, 0).dispatchEvent(new MouseEvent("click", {bubbles: true,+ clientX: bodyRect.right, clientY: bodyRect.top + bodyRect.height / 2}));+ f.render();+ check.equal(f.touch("[data-action='width']"), null, "body dividers remain available for editing and scrolling");+ f.dispose();+ }+ for (const kind of ["merged", "no-header", "disabled", "block", "link"]) {+ const f = fixture();+ const first = f.cell(0, 0);+ const rect = first.getBoundingClientRect();+ if (kind === "merged") {+ first.colSpan = 2;+ f.cell(0, 1).remove();+ }+ if (kind === "no-header") {+ f.table.tBodies[0].prepend(f.table.tHead.rows[0]);+ f.table.tHead.remove();+ }+ if (kind === "disabled") f.owner.disabled = true;+ if (kind === "block") f.setBlockMultiSelect(true);+ const link = document.createElement("a");+ if (kind === "link") first.append(link);+ (kind === "link" ? link : first).dispatchEvent(new MouseEvent("click", {bubbles: true, cancelable: true,+ clientX: rect.right, clientY: rect.top + rect.height / 2}));+ f.render();+ check.equal(!!f.touch("[data-action='width']"), kind === "no-header",+ `${kind} only exposes real, editable top-row dividers`);f.dispose();}{diff --git a/app/src/protyle/util/tableTouch.ts b/app/src/protyle/util/tableTouch.tsindex 572a4ccf75..15ad7e6e53 100644--- a/app/src/protyle/util/tableTouch.ts+++ b/app/src/protyle/util/tableTouch.ts@@ -2,8 +2,12 @@ import type {ITableGrid} from "./table";import {TABLE_VIRTUAL_ROWS} from "./tableVirtualizationDOM";import {renderMultiSelectToolbar, updateMultiSelectToolbar} from "../../mobile/util/multiSelectToolbar";import {TABLE_ADD_CONTROL_GAP, TABLE_ADD_CONTROL_THICKNESS} from "./tableResize";+import {Constants} from "../../constants";type SelectionMode = "cell" | "row" | "column";+const TABLE_TOUCH_INTERACTIVE_SELECTOR = "a, [data-type~='a'], [data-type~='block-ref'], [data-type~='file-annotation-ref'], " ++ "[data-type~='tag'], [data-type~='inline-memo'], [data-type='inline-math'], " ++ "img, input, textarea, button, select, audio, video, iframe";export interface ITableTouchState {cell: HTMLTableCellElement;@@ -19,6 +23,8 @@ export interface ITableTouchState {}interface ITableTouchActions {+ enabled: () => boolean;+ activate: (cell: HTMLTableCellElement) => boolean;state: () => ITableTouchState | undefined;select: (cell: HTMLTableCellElement, mode: SelectionMode, toggle: boolean, extend?: boolean) => boolean;range: (anchor: HTMLTableCellElement, active: HTMLTableCellElement) => void;@@ -44,6 +50,11 @@ export class TableTouchControl {private gesture?: AbortController;private scrollFrame: number;private dragging = false;+ private longPress?: {+ cell: HTMLTableCellElement, identifier: number, clientX: number, clientY: number, timer: number, selected: boolean,+ };+ private longPressContextCell?: HTMLTableCellElement;+ private columnBoundary?: {cell: HTMLTableCellElement, column: number};constructor(editor: HTMLElement, container: HTMLElement, private content: () => HTMLElement,private actions: ITableTouchActions) {@@ -87,8 +98,61 @@ export class TableTouchControl {this.toolbar.addEventListener("pointerdown", event => event.preventDefault(), {signal});this.endpoints.forEach(button => button.addEventListener("pointerdown", event =>this.startRangeDrag(event, button.dataset.endpoint === "start"), {signal}));+ document.addEventListener("touchstart", event => this.startLongPress(event, editor), {capture: true, signal});+ document.addEventListener("touchmove", event => {+ const press = this.longPress;+ if (!press) {+ return;+ }+ const point = Array.from(event.touches).find(touch => touch.identifier === press.identifier);+ if (event.touches.length !== 1 || !point) {+ this.cancelLongPress();+ } else if (press.selected) {+ event.preventDefault();+ } else if (Math.max(Math.abs(point.clientX - press.clientX), Math.abs(point.clientY - press.clientY)) >=+ Constants.SIZE_DRAG_THRESHOLD) {+ this.cancelLongPress();+ }+ }, {capture: true, passive: false, signal});+ document.addEventListener("touchend", event => {+ const press = this.longPress;+ if (!press || !Array.from(event.changedTouches).some(touch => touch.identifier === press.identifier)) {+ return;+ }+ if (press.selected) {+ event.preventDefault();+ }+ this.cancelLongPress();+ }, {capture: true, passive: false, signal});+ document.addEventListener("touchcancel", () => this.cancelLongPress(), {capture: true, signal});+ document.addEventListener("scroll", () => {+ if (!this.longPress?.selected) {+ this.cancelLongPress();+ }+ }, {capture: true, signal});+ document.addEventListener("contextmenu", event => {+ const cell = (event.target as Element).closest("td, th");+ if (cell && (cell === this.longPress?.cell || cell === this.longPressContextCell)) {+ event.preventDefault();+ event.stopImmediatePropagation();+ }+ }, {capture: true, signal});+ document.addEventListener("pointerdown", event => {+ if (event.pointerType !== "touch") {+ this.longPressContextCell = undefined;+ }+ if (this.columnBoundary && !this.controls.querySelector('[data-action="width"]')?.contains(event.target as Node)) {+ this.columnBoundary = undefined;+ this.actions.render();+ }+ }, {capture: true, signal});// 点击改变选区,滑动内容仍交给浏览器滚动,不在 pointerdown 阶段阻止默认行为。editor.addEventListener("click", event => {+ if (this.activateColumnBoundary(event, editor)) {+ event.preventDefault();+ event.stopImmediatePropagation();+ return;+ }const state = this.getState();const cell = (event.target as Element).closest<HTMLTableCellElement>("th, td");if (!state?.selection || !cell || cell.closest("table") !== state.table) {@@ -108,6 +172,8 @@ export class TableTouchControl {public reset() {this.multiSelect = false;+ this.longPressContextCell = undefined;+ this.columnBoundary = undefined;this.cancelGesture();}@@ -181,29 +247,7 @@ export class TableTouchControl {column.addEventListener("pointerdown", event => this.selectHandle(event, info.cell, "column", column));}});- if (!selection) {- const rect = cell.getBoundingClientRect();- if (rect.bottom > viewport.top && rect.top < viewport.bottom && rect.right > viewport.left && rect.left < viewport.right) {- const select = this.button(window.siyuan.languages.tableSelectRange, "iconSelect",- Math.min(rect.right, viewport.right) - 14, Math.min(rect.bottom, viewport.bottom) - 14);- select.dataset.action = "select";- select.addEventListener("pointerdown", event => event.preventDefault());- select.addEventListener("click", () => this.actions.select(cell, "cell", false));- }- }- const activeColumn = grid.cellInfos.find(info => info.cell === cell)?.col;- const column = typeof activeColumn === "number" ?- table.querySelectorAll<HTMLTableColElement>(":scope > colgroup > col")[activeColumn] : undefined;- const widthRect = column?.getBoundingClientRect() || cell.getBoundingClientRect();- if (typeof activeColumn === "number" && widthRect.right > viewport.left && widthRect.right <= viewport.right + 1) {- const width = this.button(window.siyuan.languages.width, "iconWidth", widthRect.right, viewport.top - 14);- width.dataset.action = "width";- width.addEventListener("pointerdown", event => {- event.preventDefault();- this.holdControls(event);- this.actions.width(event, cell, activeColumn);- });- }+ this.renderColumnBoundary(state);const tableRect = table.getBoundingClientRect();const addOffset = TABLE_ADD_CONTROL_GAP + TABLE_ADD_CONTROL_THICKNESS / 2;if (tableRect.bottom <= viewport.bottom + 1) {@@ -247,12 +291,12 @@ export class TableTouchControl {}}- private button(label: string, icon: string, left: number, top: number, clampToScreen = true) {+ private button(label: string, icon: string | undefined, 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.innerHTML = icon ? `<svg><use xlink:href="#${icon}"></use></svg>` : "";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);@@ -262,11 +306,123 @@ export class TableTouchControl {private getState() {const state = this.actions.state();if (state?.selection && !this.toolbar.classList.contains("fn__none")) {- state.viewport.top = Math.max(state.viewport.top, this.toolbar.getBoundingClientRect().bottom + 28);+ state.viewport.top = Math.max(state.viewport.top, this.toolbar.getBoundingClientRect().bottom + 8);}return state;}+ private activateColumnBoundary(event: MouseEvent, editor: HTMLElement) {+ const target = event.target as Element;+ const cell = target.closest<HTMLTableCellElement>("td, th");+ const table = cell?.closest("table");+ if (event.defaultPrevented || !this.actions.enabled() || event.button !== 0 ||+ event.ctrlKey || event.metaKey || event.altKey || event.shiftKey || target.closest(TABLE_TOUCH_INTERACTIVE_SELECTOR) ||+ !cell?.closest('[data-type="NodeTable"]') || cell.closest(".protyle-wysiwyg") !== editor ||+ cell.parentElement !== table.rows[0]) {+ return false;+ }+ const columns = Array.from(table.querySelectorAll<HTMLTableColElement>(":scope > colgroup > col"));+ const rect = cell.getBoundingClientRect();+ if (Math.min(Math.abs(rect.left - event.clientX), Math.abs(rect.right - event.clientX)) > 8) {+ return false;+ }+ // 首次点按仅激活表头边界,正文中的滑动和点按继续用于滚动与编辑。+ const index = columns.findIndex(column => Math.abs(column.getBoundingClientRect().right - event.clientX) <= 8);+ if (index < 0 || !this.actions.activate(cell)) {+ return false;+ }+ this.columnBoundary = {cell, column: index};+ this.actions.render();+ return true;+ }++ private renderColumnBoundary(state: ITableTouchState) {+ const boundary = this.columnBoundary;+ if (!boundary?.cell.isConnected || boundary.cell.closest("table") !== state.table) {+ return;+ }+ const {table, viewport} = state;+ const column = table.querySelectorAll<HTMLTableColElement>(":scope > colgroup > col")[boundary.column];+ const edge = column?.getBoundingClientRect().right;+ const header = boundary.cell.getBoundingClientRect();+ const top = Math.max(header.top, viewport.top);+ const bottom = Math.min(header.bottom, viewport.bottom);+ if (typeof edge !== "number" || edge <= viewport.left || edge > viewport.right + 1 || bottom <= top) {+ return;+ }+ const guide = document.createElement("div");+ guide.className = "protyle-table-control__width-guide";+ guide.style.left = `${edge}px`;+ guide.style.top = `${viewport.top}px`;+ guide.style.height = `${viewport.bottom - viewport.top}px`;+ this.controls.append(guide);+ const width = this.button(window.siyuan.languages.width, undefined, edge, (top + bottom) / 2, false);+ width.className = "protyle-table-control__handle protyle-table-control__width";+ width.style.height = `${bottom - top}px`;+ width.dataset.action = "width";+ width.setAttribute("aria-pressed", "true");+ width.addEventListener("pointerdown", event => {+ if (event.button !== 0 || !this.actions.enabled()) {+ return;+ }+ event.preventDefault();+ event.stopPropagation();+ this.holdControls(event);+ Array.from(this.controls.children).forEach(control => {+ if (control !== width && control !== guide) {+ control.classList.add("fn__none");+ }+ });+ this.actions.width(event, boundary.cell, boundary.column);+ document.addEventListener("pointermove", move => {+ if (move.pointerId === event.pointerId) {+ const left = `${column.getBoundingClientRect().right}px`;+ guide.style.left = left;+ width.style.left = left;+ }+ }, {signal: this.gesture.signal});+ });+ }++ private startLongPress(event: TouchEvent, editor: HTMLElement) {+ this.cancelLongPress();+ this.longPressContextCell = undefined;+ const target = event.target as Element;+ const cell = target.closest<HTMLTableCellElement>("td, th");+ if (event.defaultPrevented || event.touches.length !== 1 || !this.actions.enabled() ||+ this.actions.state()?.selection || !cell?.closest('[data-type="NodeTable"]') ||+ cell.closest(".protyle-wysiwyg") !== editor || editor.closest(".fn__none, [inert]") ||+ cell.closest(`tr[${TABLE_VIRTUAL_ROWS}]`) || cell.querySelector(".table__cell-editor") ||+ target.closest(TABLE_TOUCH_INTERACTIVE_SELECTOR)) {+ return;+ }+ const {identifier, clientX, clientY} = event.touches[0];+ const press = {cell, identifier, clientX, clientY, timer: 0, selected: false};+ this.longPress = press;+ // 仅在待识别的单元格上关闭原生选词,编辑中的单元格保留文字长按行为。+ cell.classList.add("table__cell--touch-selecting");+ press.timer = window.setTimeout(() => {+ if (!this.actions.enabled() || !cell.isConnected || cell.querySelector(".table__cell-editor")) {+ this.cancelLongPress();+ return;+ }+ press.selected = this.actions.select(cell, "cell", false);+ if (press.selected) {+ this.longPressContextCell = cell;+ } else {+ this.cancelLongPress();+ }+ }, Constants.TIMEOUT_LONGPRESS);+ }++ private cancelLongPress() {+ if (this.longPress) {+ clearTimeout(this.longPress.timer);+ this.longPress.cell.classList.remove("table__cell--touch-selecting");+ this.longPress = undefined;+ }+ }+private selectHandle(event: PointerEvent, cell: HTMLTableCellElement, mode: "row" | "column", handle: HTMLElement) {if (event.button !== 0) {return;@@ -401,6 +557,7 @@ export class TableTouchControl {}private cancelGesture() {+ this.cancelLongPress();this.gesture?.abort();this.gesture = undefined;this.dragging = false;