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 the manually resized database cell input size https://github.com/siyuan-note/siyuan/issues/20440
Daniel6c06f4d19ea2
diff --git a/app/src/dialog/anchoredInputPosition.ts b/app/src/dialog/anchoredInputPosition.tsindex 94a72490f0..1916ce7b80 100644--- a/app/src/dialog/anchoredInputPosition.ts+++ b/app/src/dialog/anchoredInputPosition.ts@@ -4,6 +4,16 @@ export const bindAnchoredInputPosition = (inputElement: HTMLElement, getAnchor:let frame = 0;let disposed = false;let observedAnchor: HTMLElement;+ // 记录最近一次写入的尺寸;内联尺寸与之不同说明用户拖拽调整过大小,此后仅更新位置+ let appliedWidth = "";+ let appliedHeight = "";+ let keepSize = false;+ const applySize = (width: number, height: number) => {+ appliedWidth = `${width}px`;+ appliedHeight = `${height}px`;+ inputElement.style.width = appliedWidth;+ inputElement.style.height = appliedHeight;+ };const update = () => {frame = 0;const anchorElement = getAnchor();@@ -22,6 +32,10 @@ export const bindAnchoredInputPosition = (inputElement: HTMLElement, getAnchor:resizeObserver?.observe(anchorElement);observedAnchor = anchorElement;}+ if (!keepSize && appliedWidth &&+ (inputElement.style.width !== appliedWidth || inputElement.style.height !== appliedHeight)) {+ keepSize = true;+ }const cellRect = anchorElement.getBoundingClientRect();const maskRect = maskElement.getBoundingClientRect();const contentRect = contentElement?.getBoundingClientRect();@@ -31,20 +45,24 @@ export const bindAnchoredInputPosition = (inputElement: HTMLElement, getAnchor:const viewportTop = viewport?.offsetTop || 0;const viewportWidth = viewport?.width || window.innerWidth;const viewportHeight = viewport?.height || window.innerHeight;- const width = Math.min(Math.max(cellRect.width, 240), Math.max(0, viewportWidth - 16));- inputElement.style.width = `${width}px`;- inputElement.style.height = "auto";- const height = Math.min(Math.max(cellRect.height, inputElement.scrollHeight), Math.max(0, viewportHeight - 16));+ let width = parseFloat(inputElement.style.width);+ let height = parseFloat(inputElement.style.height);+ if (!keepSize) {+ width = Math.min(Math.max(cellRect.width, 240), Math.max(0, viewportWidth - 16));+ inputElement.style.width = `${width}px`;+ inputElement.style.height = "auto";+ height = Math.min(Math.max(cellRect.height, inputElement.scrollHeight), Math.max(0, viewportHeight - 16));+ applySize(width, height);+ }const left = Math.max(viewportLeft + 8, Math.min(cellRect.left, viewportLeft + viewportWidth - width - 8));const top = Math.max(viewportTop + 8, Math.min(cellRect.top, viewportTop + viewportHeight - height - 8));inputElement.style.left = `${left - maskRect.left}px`;inputElement.style.top = `${top - maskRect.top}px`;- inputElement.style.height = `${height}px`;inputElement.style.visibility = "";return;}- const width = contentRect ? Math.min(Math.max(cellRect.width, 25), contentRect.width) :- Math.max(cellRect.width, 25);+ const width = keepSize ? parseFloat(inputElement.style.width) :+ contentRect ? Math.min(Math.max(cellRect.width, 25), contentRect.width) : Math.max(cellRect.width, 25);const left = contentRect && (cellRect.left < contentRect.left || cellRect.left + width > contentRect.right) ?contentRect.left : cellRect.left;const height = contentRect ? Math.max(0, Math.min(cellRect.bottom, contentRect.bottom) - cellRect.top) :@@ -52,8 +70,9 @@ export const bindAnchoredInputPosition = (inputElement: HTMLElement, getAnchor:// 输入框位于独立遮罩中,使用当前单元格坐标并扣除遮罩原点,保持滚动和视口变化后的对齐。inputElement.style.top = `${cellRect.top - maskRect.top}px`;inputElement.style.left = `${left - maskRect.left}px`;- inputElement.style.width = `${width}px`;- inputElement.style.height = `${height}px`;+ if (!keepSize) {+ applySize(width, height);+ }inputElement.style.visibility = height > 0 ? "" : "hidden";};const schedule = () => {diff --git a/app/src/protyle/render/av/cellInputPosition.test.ts b/app/src/protyle/render/av/cellInputPosition.test.tsindex 57b374b4a8..7f1ae9691c 100644--- a/app/src/protyle/render/av/cellInputPosition.test.ts+++ b/app/src/protyle/render/av/cellInputPosition.test.ts@@ -267,3 +267,28 @@ test("batch inputs opened below a menu keep menu positioning instead of cell traassert.equal(fixture.menuPositioned, true);assert.equal(fixture.getAnchor, undefined);});++test("anchored input keeps a manually resized size while it follows the anchor", () => {+ const fixture = setup();+ assert.equal(fixture.input.style.width, "220px");+ // 模拟拖拽输入框右下角后浏览器写入的内联尺寸+ fixture.input.style.width = "300px";+ fixture.input.style.height = "120px";+ fixture.anchor.rect = rect(40, 280, 220, 36);+ fixture.window.dispatchEvent(new Event("scroll"));+ fixture.flush();+ assert.equal(fixture.input.style.width, "300px");+ assert.equal(fixture.input.style.height, "120px");+ assert.equal(fixture.input.style.top, "280px");+ fixture.dispose();++ const fit = setup(true);+ fit.input.style.width = "200px";+ fit.input.style.height = "90px";+ fit.input.dispatchEvent(new Event("input"));+ fit.flush();+ assert.equal(fit.input.style.width, "200px");+ assert.equal(fit.input.style.height, "90px");+ assert.equal(fit.input.style.top, "500px");+ fit.dispose();+});