An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Keep mind map pinch gestures from reopening the keyboard https://github.com/siyuan-note/siyuan/issues/20776
Daniel565be5908bd7
diff --git a/app/src/protyle/render/listMindmap/model.test.ts b/app/src/protyle/render/listMindmap/model.test.tsindex 9bc9783705..4a1bd32eb7 100644--- a/app/src/protyle/render/listMindmap/model.test.ts+++ b/app/src/protyle/render/listMindmap/model.test.ts@@ -3386,6 +3386,13 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,check.deepEqual([panView.scale, panView.offsetX, panView.offsetY], readingTransform);check.equal(panView.interactionActive, false);scrollHost.scrollTop = 0;+ const externalEditor = document.createElement("div");+ externalEditor.contentEditable = "true";+ externalEditor.textContent = "Outside editor";+ externalEditor.style.cssText = "position:fixed;top:0;left:0;z-index:1000;background:white";+ document.body.append(externalEditor);+ externalEditor.focus({preventScroll: true});+ getSelection().collapse(externalEditor.firstChild, 2);await nativeTouch([{type: "touchStart", touchPoints: [fingerAt(1), fingerAt(2, 100)]},{type: "touchMove", touchPoints: [fingerAt(1, 30, -20), fingerAt(2, 130, -20)]},@@ -3397,6 +3404,16 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,check.notEqual(panView.offsetX, readingTransform[1], "native two-finger input pans the reading canvas");check.equal(panView.interactionActive, false);check.equal(scrollHost.scrollTop, 0, "explicit two-finger input does not scroll the document");+ check.equal(document.activeElement, panHost, "a native pinch leaves focus on the non-editable canvas");+ check.equal(panHost.isContentEditable, false);+ check.equal(getSelection().anchorNode, externalEditor.firstChild, "focus transfer retains the document caret");+ const externalPoint = centerPoint(externalEditor);+ await nativeTouch([+ {type: "touchStart", touchPoints: [{id: 3, ...externalPoint}]},+ {type: "touchEnd", touchPoints: []},+ ]);+ check.equal(document.activeElement, externalEditor, "tapping text after a pinch restores normal editing focus");+ externalEditor.remove();panView.scale = readingTransform[0];panView.offsetX = readingTransform[1];panView.offsetY = readingTransform[2];diff --git a/app/src/protyle/render/listMindmap/pinch.test.ts b/app/src/protyle/render/listMindmap/pinch.test.tsindex 2b7a1c7a9b..d69e74786e 100644--- a/app/src/protyle/render/listMindmap/pinch.test.ts+++ b/app/src/protyle/render/listMindmap/pinch.test.ts@@ -17,18 +17,34 @@ const compiled = transpileModule(`class View {globalThis.View = View;`, {compilerOptions: {target: ScriptTarget.ES2021}}).outputText;const setup = () => {- const context: any = {clearTimeout};+ class Element {+ isContentEditable = false;+ input = false;+ inside = false;+ matches() { return this.input; }+ }+ const document = {activeElement: new Element()};+ const host = {+ ownerDocument: document,+ contains: (element: Element) => element.inside,+ focus: (options: {preventScroll: boolean}) => {+ assert.equal(options.preventScroll, true);+ document.activeElement = Object.assign(new Element(), {inside: true});+ },+ };+ const context: any = {clearTimeout, HTMLElement: Element};runInNewContext(compiled, context);const target = new context.View();let cancelled = 0;Object.assign(target, {scale: 1, offsetX: 0, offsetY: 0, pinching: false, interactionActive: false,+ options: {host},viewport: {contains: (element: {outside?: boolean} | null) => !!element && !element.outside,getBoundingClientRect: () => ({left: 10, top: 20})},cancelPointer: () => { cancelled++; target.pendingPointerId = undefined; },boundedPan: (x: number, y: number) => ({x, y}), draw: () => {},});- return {target, cancelled: () => cancelled};+ return {target, document, cancelled: () => cancelled};};const touch = (clientX: number, clientY = 120, excluded = false, outside = false) => ({@@ -145,3 +161,44 @@ test("additional contacts cancel a pending node hold even when a control or thirassert.equal(target.pinching, false);}});++test("a valid pinch transfers external editing focus to the canvas without restoring it on release", () => {+ for (const property of ["isContentEditable", "input"] as const) {+ const {target, document} = setup();+ const editor = document.activeElement;+ editor[property] = true;+ target.pinchStart(event(touch(60), touch(160)));+ assert.notEqual(document.activeElement, editor);+ assert.equal(document.activeElement.inside, true);+ target.pinchEnd(event(touch(60)));+ target.pinchEnd(event());+ assert.equal(document.activeElement.inside, true);+ }+});++test("pinches preserve internal editing and non-editable focus", () => {+ for (const editing of [false, true]) {+ const {target, document} = setup();+ const active = document.activeElement;+ active.inside = editing;+ active.isContentEditable = editing;+ target.pinchStart(event(touch(60), touch(160)));+ assert.equal(document.activeElement, active);+ }+});++test("single touches, excluded controls, outside contacts and locked maps preserve external editing focus", () => {+ for (const {locked, contacts} of [+ {locked: false, contacts: [touch(60)]},+ {locked: false, contacts: [touch(60), touch(160, 120, true)]},+ {locked: false, contacts: [touch(60), touch(160, 120, false, true)]},+ {locked: true, contacts: [touch(60), touch(160)]},+ ]) {+ const {target, document} = setup();+ const active = document.activeElement;+ active.isContentEditable = true;+ target.locked = locked;+ target.pinchStart(event(...contacts));+ assert.equal(document.activeElement, active);+ }+});diff --git a/app/src/protyle/render/listMindmap/view.ts b/app/src/protyle/render/listMindmap/view.tsindex 207fbf5557..042a79c5aa 100644--- a/app/src/protyle/render/listMindmap/view.ts+++ b/app/src/protyle/render/listMindmap/view.ts@@ -2252,6 +2252,12 @@ export class ListMindmapView {event.preventDefault();this.cancelPointer();clearTimeout(this.linkTimer);+ // 双指操作转移外部编辑焦点,避免鸿蒙在松手后重新唤起输入法。+ const active = this.options.host.ownerDocument.activeElement;+ if (active instanceof HTMLElement && !this.options.host.contains(active) &&+ (active.isContentEditable || active.matches("input, textarea"))) {+ this.options.host.focus({preventScroll: true});+ }this.suppressLinkClick = true;this.pinching = true;const [first, second] = Array.from(event.touches);