Skip to content

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

:art: https://github.com/siyuan-note/siyuan/issues/18529

Vanessaefa4b9c2d0ac
diff --git a/app/src/mobile/util/keyboardToolbar.ts b/app/src/mobile/util/keyboardToolbar.ts
index e2d51cadcb..c979775985 100644
--- a/app/src/mobile/util/keyboardToolbar.ts
+++ b/app/src/mobile/util/keyboardToolbar.ts
@@ -462,6 +462,7 @@ const renderKeyboardToolbar = () => {
const range = getSelection().getRangeAt(0);
const isProtyle = hasClosestByClassName(range.startContainer, "protyle-wysiwyg", true);
const nodeElement = hasClosestBlock(range.startContainer);
+ const endNodeElement = hasClosestBlock(range.endContainer);
if (!isProtyle || !nodeElement ||
hasClosestByAttribute(range.startContainer, "data-type", "av-search")) {
dynamicElements[0].classList.add("fn__none");
@@ -470,6 +471,14 @@ const renderKeyboardToolbar = () => {
}
const selectText = range.toString();
+ const startCellElement = hasClosestByTag(range.startContainer, "TD") ||
+ hasClosestByTag(range.startContainer, "TH");
+ const endCellElement = hasClosestByTag(range.endContainer, "TD") ||
+ hasClosestByTag(range.endContainer, "TH");
+ const disableLink = (!!endNodeElement && nodeElement !== endNodeElement) ||
+ (!!startCellElement && !!endCellElement && startCellElement !== endCellElement);
+ dynamicElements[1].querySelector('[data-type="a"]').toggleAttribute("disabled", disableLink);
+ dynamicElements[1].querySelector('[data-type="block-ref"]').toggleAttribute("disabled", disableLink);
if (!nodeElement.classList.contains("code-block") &&
(selectText || dynamicElements[0].querySelector('[data-type="goinline"]').classList.contains("protyle-toolbar__item--current"))) {
diff --git a/app/src/mobile/util/mobileAppUtil.test.ts b/app/src/mobile/util/mobileAppUtil.test.ts
new file mode 100644
index 0000000000..62e35e1e5a
--- /dev/null
+++ b/app/src/mobile/util/mobileAppUtil.test.ts
@@ -0,0 +1,52 @@
+import {describe, it} from "node:test";
+import * as assert from "node:assert/strict";
+import {canInput} from "./mobileAppUtil";
+
+const createElement = (options: {
+ tagName?: string,
+ classNames?: string[],
+ attributes?: Record<string, string>,
+ parentElement?: HTMLElement,
+}) => {
+ const attributes = options.attributes || {};
+ return {
+ nodeType: 1,
+ tagName: options.tagName || "DIV",
+ parentElement: options.parentElement || null,
+ classList: {
+ contains: (className: string) => options.classNames?.includes(className) || false,
+ },
+ getAttribute: (name: string) => attributes[name] ?? null,
+ hasAttribute: (name: string) => Object.prototype.hasOwnProperty.call(attributes, name),
+ } as unknown as HTMLElement;
+};
+
+describe("mobile input detection", () => {
+ it("accepts the editable Protyle root as the active element", () => {
+ const bodyElement = createElement({tagName: "BODY"});
+ const wysiwygElement = createElement({
+ classNames: ["protyle-wysiwyg"],
+ attributes: {
+ contenteditable: "true",
+ "data-readonly": "false",
+ },
+ parentElement: bodyElement,
+ });
+
+ assert.equal(canInput(wysiwygElement), wysiwygElement);
+ });
+
+ it("rejects a readonly Protyle root", () => {
+ const bodyElement = createElement({tagName: "BODY"});
+ const wysiwygElement = createElement({
+ classNames: ["protyle-wysiwyg"],
+ attributes: {
+ contenteditable: "false",
+ "data-readonly": "true",
+ },
+ parentElement: bodyElement,
+ });
+
+ assert.equal(canInput(wysiwygElement), false);
+ });
+});
diff --git a/app/src/mobile/util/touch.ts b/app/src/mobile/util/touch.ts
index ab18ca4ee6..350e6e07ef 100644
--- a/app/src/mobile/util/touch.ts
+++ b/app/src/mobile/util/touch.ts
@@ -269,6 +269,16 @@ export const handleTouchStart = (event: TouchEvent) => {
const blockElement = hasClosestBlock(target);
if (blockElement && editor.protyle.wysiwyg.element.contains(blockElement)) {
longPressTimer = window.setTimeout(() => {
+ const selection = window.getSelection();
+ if (selection?.rangeCount > 0) {
+ const range = selection.getRangeAt(0);
+ if (!range.collapsed && range.toString().replace(Constants.ZWSP, "") !== "" &&
+ editor.protyle.wysiwyg.element.contains(range.startContainer) &&
+ editor.protyle.wysiwyg.element.contains(range.endContainer)) {
+ longPressTimer = undefined;
+ return;
+ }
+ }
window.getSelection()?.removeAllRanges();
editor.protyle.toolbar.showMultiSelectMode(editor.protyle, blockElement);
if (editor.protyle.options.render.gutter) {
diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.ts
index b48b18f3a7..8dbbfdd7df 100644
--- a/app/src/protyle/util/onGet.ts
+++ b/app/src/protyle/util/onGet.ts
@@ -450,15 +450,12 @@ export const enableProtyle = (protyle: IProtyle) => {
}
protyle.disabled = false;
if (isMobile()) {
- // Android 端空块输入法弹出会收起 https://ld246.com/article/1689713888289
- // iPhone,iPad 端 protyle.wysiwyg.element contenteditable 为 true 时,输入会在块中间插入 span 导致保存失败 https://ld246.com/article/1643473862873/comment/1643813765839#comments
/// #if MOBILE
updateMobileTitleReadonly(protyle);
/// #endif
- } else {
- protyle.wysiwyg.element.setAttribute("contenteditable", "true");
- protyle.wysiwyg.element.style.userSelect = "";
}
+ protyle.wysiwyg.element.setAttribute("contenteditable", "true");
+ protyle.wysiwyg.element.style.userSelect = "";
// 用于区分移动端样式
protyle.wysiwyg.element.setAttribute("data-readonly", "false");
if (protyle.title && protyle.title.editElement) {