Skip to content

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

:bug: Keep mobile settings inputs visible when the keyboard opens https://github.com/siyuan-note/siyuan/issues/19142

Vanessabe35004ec679
diff --git a/app/src/assets/scss/main/_mobile.scss b/app/src/assets/scss/main/_mobile.scss
index 31f87b78ac..cfd6b8fea6 100644
--- a/app/src/assets/scss/main/_mobile.scss
+++ b/app/src/assets/scss/main/_mobile.scss
@@ -1416,6 +1416,7 @@ body.mobile-topbar--merged {
.b3-dialog__container {
max-width: 100vw;
+ max-height: 100%;
}
@media (max-width: 620px) {
diff --git a/app/src/mobile/index.ts b/app/src/mobile/index.ts
index e91a8147b7..27c601a26a 100644
--- a/app/src/mobile/index.ts
+++ b/app/src/mobile/index.ts
@@ -61,6 +61,7 @@ import {initHarmonyTextSelectionMenu} from "../util/harmonyTextSelectionMenu";
import {updateMobileTopBarLayout} from "./util/mobileTopBar";
import {showMobileBars} from "./util/mobileBars";
import {initializeEnglishCommandTranslations} from "../command/english";
+import {scrollInputIntoView} from "./util/visibleViewport";
class App {
public plugins: import("../plugin").Plugin[] = [];
@@ -124,9 +125,7 @@ class App {
const editableElement = canInput(event.target);
if (editableElement && ["INPUT", "TEXTAREA"].includes(editableElement.tagName)) {
setTimeout(() => {
- editableElement.scrollIntoView({
- block: "center",
- });
+ scrollInputIntoView(editableElement);
}, Constants.TIMEOUT_TRANSITION);
}
if (editableElement) {
diff --git a/app/src/mobile/util/visibleViewport.ts b/app/src/mobile/util/visibleViewport.ts
index b72caa68a3..cb0f6ac90a 100644
--- a/app/src/mobile/util/visibleViewport.ts
+++ b/app/src/mobile/util/visibleViewport.ts
@@ -12,3 +12,30 @@ export const getVisibleViewportBounds = () => {
bottom: window.innerHeight,
};
};
+
+export const scrollInputIntoView = (element: Element) => {
+ if (!element.isConnected || document.activeElement !== element) {
+ return;
+ }
+ const viewport = getVisibleViewportBounds();
+ let parent = element.parentElement;
+ while (parent && parent !== document.body && parent !== document.documentElement) {
+ if (/^(auto|scroll)$/.test(getComputedStyle(parent).overflowY) && parent.scrollHeight > parent.clientHeight) {
+ const parentRect = parent.getBoundingClientRect();
+ const top = Math.max(viewport.top, parentRect.top + parent.clientTop);
+ const bottom = Math.min(viewport.bottom, parentRect.top + parent.clientTop + parent.clientHeight);
+ const rect = element.getBoundingClientRect();
+ if (bottom <= top) {
+ return;
+ }
+ // 只滚动输入框所在的容器,避免将弹窗和页面一起上移;高于可见区域的输入框保留当前位置。
+ if (rect.top < top && rect.bottom < bottom) {
+ parent.scrollTop += Math.max(rect.top - top, rect.bottom - bottom);
+ } else if (rect.bottom > bottom && rect.top > top) {
+ parent.scrollTop += Math.min(rect.bottom - bottom, rect.top - top);
+ }
+ return;
+ }
+ parent = parent.parentElement;
+ }
+};