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 mobile block hint input visible https://github.com/siyuan-note/siyuan/issues/19037
Daniel4a5081bfb4b9
diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.tsindex 673d672114..7cf0d68358 100644--- a/app/src/protyle/hint/index.ts+++ b/app/src/protyle/hint/index.ts@@ -351,6 +351,39 @@ export class Hint {Constants.BLOCK_HINT_CLOSE_KEYS[this.splitChar], Constants.SIZE_TITLE);}+ private getMobileSelectionBounds(protyle: IProtyle) {+ const range = getEditorRange(protyle.wysiwyg.element);+ const position = getSelectionPosition(protyle.wysiwyg.element, range);+ if (range.startContainer.nodeType === 3 && range.startContainer.textContent.length > 0) {+ const textLength = range.startContainer.textContent.length;+ const offset = Math.min(range.startOffset, textLength);+ const textRange = range.cloneRange();+ if (offset > 0) {+ textRange.setStart(range.startContainer, offset - 1);+ textRange.setEnd(range.startContainer, offset);+ } else {+ textRange.setStart(range.startContainer, 0);+ textRange.setEnd(range.startContainer, 1);+ }+ const rects = textRange.getClientRects();+ const rect = rects[rects.length - 1];+ if (rect?.height > 0) {+ return {+ top: rect.top,+ bottom: rect.bottom,+ };+ }+ }+ const rangeElement = range.startContainer.nodeType === 3 ?+ range.startContainer.parentElement : range.startContainer as HTMLElement;+ const computedLineHeight = rangeElement ? parseFloat(getComputedStyle(rangeElement).lineHeight) : NaN;+ const lineHeight = Number.isNaN(computedLineHeight) ? 26 : computedLineHeight;+ return {+ top: position.top - lineHeight,+ bottom: position.top + lineHeight,+ };+ }+private setMobilePosition(anchorTop: number, anchorBottom: number) {const viewportBounds = getVisibleViewportBounds();const viewportTop = Math.max(viewportBounds.top, getTopBarHeight());@@ -360,12 +393,13 @@ export class Hint {viewportBottom = Math.min(viewportBottom, keyboardToolbarElement.getBoundingClientRect().top);}viewportBottom = Math.max(viewportTop, viewportBottom);- const heightLimit = (viewportBottom - viewportTop) / 2;+ const heightLimit = (viewportBottom - viewportTop) / 3;+ const gap = 4;let position = getMobileHintPosition(anchorTop, anchorBottom, this.element.scrollHeight,- viewportTop, viewportBottom, heightLimit);+ viewportTop, viewportBottom, heightLimit, gap);this.element.style.maxHeight = `${position.maxHeight}px`;position = getMobileHintPosition(anchorTop, anchorBottom, this.element.getBoundingClientRect().height,- viewportTop, viewportBottom, heightLimit);+ viewportTop, viewportBottom, heightLimit, gap);this.element.style.left = "0";this.element.style.top = `${position.top}px`;}@@ -390,7 +424,8 @@ export class Hint {/// #if !MOBILEsetPosition(this.element, textareaPosition.left, textareaPosition.top + 26, 30);/// #else- this.setMobilePosition(textareaPosition.top, textareaPosition.top + 26);+ const selectionBounds = this.getMobileSelectionBounds(protyle);+ this.setMobilePosition(selectionBounds.top, selectionBounds.bottom);/// #endif}} else if (!this.element.querySelector(".fn__loading")) {@@ -487,7 +522,8 @@ export class Hint {/// #if !MOBILEsetPosition(this.element, textareaPosition.left, textareaPosition.top + 26, 30);/// #else- this.setMobilePosition(textareaPosition.top, textareaPosition.top + 26);+ const selectionBounds = this.getMobileSelectionBounds(protyle);+ this.setMobilePosition(selectionBounds.top, selectionBounds.bottom);/// #endif}this.element.scrollTop = 0;diff --git a/app/src/protyle/hint/mobileHintPosition.test.ts b/app/src/protyle/hint/mobileHintPosition.test.tsindex 2a33eecd9f..abb7d7d789 100644--- a/app/src/protyle/hint/mobileHintPosition.test.ts+++ b/app/src/protyle/hint/mobileHintPosition.test.ts@@ -41,4 +41,15 @@ describe("getMobileHintPosition", () => {top: 194,});});++ it("leaves a gap around the caret line", () => {+ assert.deepEqual(getMobileHintPosition(420, 446, 200, 48, 500, Infinity, 4), {+ maxHeight: 368,+ top: 216,+ });+ assert.deepEqual(getMobileHintPosition(80, 106, 200, 48, 500, Infinity, 4), {+ maxHeight: 390,+ top: 110,+ });+ });});diff --git a/app/src/protyle/hint/mobileHintPosition.ts b/app/src/protyle/hint/mobileHintPosition.tsindex 9c7e54c28a..b64cf37815 100644--- a/app/src/protyle/hint/mobileHintPosition.ts+++ b/app/src/protyle/hint/mobileHintPosition.ts@@ -1,14 +1,15 @@export const getMobileHintPosition = (anchorTop: number, anchorBottom: number, hintHeight: number,- viewportTop: number, viewportBottom: number, heightLimit = Infinity) => {+ 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));- const spaceAbove = visibleAnchorTop - viewportTop;- const spaceBelow = viewportBottom - visibleAnchorBottom;+ const spaceAbove = Math.max(0, visibleAnchorTop - viewportTop - gap);+ 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 : visibleAnchorTop - height,+ top: below ? visibleAnchorBottom + gap : visibleAnchorTop - gap - height,};};