Skip to content

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

:bug: Pin mobile block hints above the input line https://github.com/siyuan-note/siyuan/issues/19037

Daniel0d7c2129961f
diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.ts
index 7cf0d68358..8546b56d85 100644
--- a/app/src/protyle/hint/index.ts
+++ b/app/src/protyle/hint/index.ts
@@ -395,11 +395,9 @@ export class Hint {
viewportBottom = Math.max(viewportTop, viewportBottom);
const heightLimit = (viewportBottom - viewportTop) / 3;
const gap = 4;
- let position = getMobileHintPosition(anchorTop, anchorBottom, this.element.scrollHeight,
- viewportTop, viewportBottom, heightLimit, gap);
+ const position = getMobileHintPosition(anchorTop, anchorBottom, viewportTop, viewportBottom,
+ heightLimit, gap);
this.element.style.maxHeight = `${position.maxHeight}px`;
- position = getMobileHintPosition(anchorTop, anchorBottom, this.element.getBoundingClientRect().height,
- viewportTop, viewportBottom, heightLimit, gap);
this.element.style.left = "0";
this.element.style.top = `${position.top}px`;
}
diff --git a/app/src/protyle/hint/mobileHintPosition.test.ts b/app/src/protyle/hint/mobileHintPosition.test.ts
index abb7d7d789..24b54a1ed2 100644
--- a/app/src/protyle/hint/mobileHintPosition.test.ts
+++ b/app/src/protyle/hint/mobileHintPosition.test.ts
@@ -4,50 +4,50 @@ import {getMobileHintPosition} from "./mobileHintPosition";
describe("getMobileHintPosition", () => {
it("places the hint below the caret when more space is available there", () => {
- assert.deepEqual(getMobileHintPosition(80, 106, 200, 48, 500), {
+ assert.deepEqual(getMobileHintPosition(80, 106, 48, 500), {
maxHeight: 394,
top: 106,
});
});
it("places the hint above the caret without covering it", () => {
- assert.deepEqual(getMobileHintPosition(420, 446, 200, 48, 500), {
+ assert.deepEqual(getMobileHintPosition(420, 446, 48, 500), {
maxHeight: 372,
- top: 220,
+ top: 48,
});
});
it("limits the hint to the available space above the caret", () => {
- assert.deepEqual(getMobileHintPosition(180, 206, 300, 48, 250), {
+ assert.deepEqual(getMobileHintPosition(180, 206, 48, 250), {
maxHeight: 132,
top: 48,
});
});
it("keeps the hint inside the viewport when the caret is obscured", () => {
- assert.deepEqual(getMobileHintPosition(540, 566, 200, 48, 500), {
+ assert.deepEqual(getMobileHintPosition(540, 566, 48, 500), {
maxHeight: 452,
- top: 300,
+ top: 48,
});
- assert.deepEqual(getMobileHintPosition(10, 36, 200, 48, 500), {
+ assert.deepEqual(getMobileHintPosition(10, 36, 48, 500), {
maxHeight: 452,
top: 48,
});
});
it("limits the hint to part of the visible viewport", () => {
- assert.deepEqual(getMobileHintPosition(420, 446, 400, 48, 500, 226), {
+ assert.deepEqual(getMobileHintPosition(420, 446, 48, 500, 226), {
maxHeight: 226,
- top: 194,
+ top: 48,
});
});
it("leaves a gap around the caret line", () => {
- assert.deepEqual(getMobileHintPosition(420, 446, 200, 48, 500, Infinity, 4), {
+ assert.deepEqual(getMobileHintPosition(420, 446, 48, 500, Infinity, 4), {
maxHeight: 368,
- top: 216,
+ top: 48,
});
- assert.deepEqual(getMobileHintPosition(80, 106, 200, 48, 500, Infinity, 4), {
+ assert.deepEqual(getMobileHintPosition(80, 106, 48, 500, Infinity, 4), {
maxHeight: 390,
top: 110,
});
diff --git a/app/src/protyle/hint/mobileHintPosition.ts b/app/src/protyle/hint/mobileHintPosition.ts
index b64cf37815..94daf730ae 100644
--- a/app/src/protyle/hint/mobileHintPosition.ts
+++ b/app/src/protyle/hint/mobileHintPosition.ts
@@ -1,5 +1,5 @@
-export const getMobileHintPosition = (anchorTop: number, anchorBottom: number, hintHeight: number,
- viewportTop: number, viewportBottom: number, heightLimit = Infinity,
+export const getMobileHintPosition = (anchorTop: number, anchorBottom: number, viewportTop: number,
+ viewportBottom: number, heightLimit = Infinity,
gap = 0) => {
const visibleAnchorTop = Math.max(viewportTop, Math.min(anchorTop, viewportBottom));
const visibleAnchorBottom = Math.max(visibleAnchorTop, Math.min(anchorBottom, viewportBottom));
@@ -7,9 +7,8 @@ export const getMobileHintPosition = (anchorTop: number, anchorBottom: number, h
const spaceBelow = Math.max(0, viewportBottom - visibleAnchorBottom - gap);
const below = spaceBelow >= spaceAbove;
const maxHeight = Math.min(below ? spaceBelow : spaceAbove, Math.max(0, heightLimit));
- const height = Math.min(hintHeight, maxHeight);
return {
maxHeight,
- top: below ? visibleAnchorBottom + gap : visibleAnchorTop - gap - height,
+ top: below ? visibleAnchorBottom + gap : viewportTop,
};
};