Vanessa 2026-02-04 19:22:32 +08:00
parent 0328020aec
commit d25a2ce718
5 changed files with 44 additions and 5 deletions

View file

@ -79,6 +79,23 @@ export const onGetConfig = (isStart: boolean, app: App) => {
let resizeTimeout = 0;
let firstResize = true;
window.addEventListener("resize", () => {
/// #if MOBILE
// 获取键盘高度
window.siyuan.mobile.size.isLandscape = window.matchMedia && window.matchMedia("(orientation: landscape)").matches;
if (window.siyuan.mobile.size.isLandscape) {
if (window.innerHeight < window.siyuan.mobile.size.landscape.height1) {
window.siyuan.mobile.size.landscape.height2 = window.innerHeight;
} else {
window.siyuan.mobile.size.landscape.height1 = window.innerHeight;
}
} else {
if (window.innerHeight < window.siyuan.mobile.size.portrait.height1) {
window.siyuan.mobile.size.portrait.height2 = window.innerHeight;
} else {
window.siyuan.mobile.size.portrait.height1 = window.innerHeight;
}
}
/// #endif
if (firstResize) {
recordBeforeResizeTop();
firstResize = false;

View file

@ -53,6 +53,17 @@ class App {
dialogs: [],
blockPanels: [],
mobile: {
size: {
isLandscape: window.matchMedia && window.matchMedia("(orientation: landscape)").matches,
landscape: {
height1: window.innerHeight,
height2: window.innerHeight,
}, // 横屏
portrait: {
height1: window.innerHeight,
height2: window.innerHeight,
}
},
docks: {
outline: null,
file: null,

View file

@ -288,8 +288,8 @@ export const showKeyboardToolbarUtil = (oldScrollTop: number) => {
showUtil = true;
const toolbarElement = document.getElementById("keyboardToolbar");
const keyboardHeight = ((document.documentElement.clientHeight - window.visualViewport.height) ||
(window.outerHeight / 2 - 42)) + "px";
const keyboardHeight = ((window.siyuan.mobile.size.isLandscape ? window.siyuan.mobile.size.landscape.height1 - window.siyuan.mobile.size.landscape.height2 : window.siyuan.mobile.size.portrait.height1 - window.siyuan.mobile.size.portrait.height2) ||
(window.innerHeight / 2 - 42)) + "px";
const editor = getCurrentEditor();
if (editor) {
editor.protyle.element.parentElement.style.paddingBottom = keyboardHeight;

View file

@ -417,9 +417,9 @@ export const cellScrollIntoView = (blockElement: HTMLElement, cellElement: Eleme
/// #if MOBILE
const contentElement = hasClosestByClassName(blockElement, "protyle-content", true);
if (contentElement && cellElement.getAttribute("data-dtype") !== "checkbox") {
const keyboardH = document.documentElement.clientHeight - window.visualViewport.height;
if (cellRect.bottom > window.innerHeight - keyboardH - 42) {
contentElement.scrollTop += cellRect.bottom - window.innerHeight + 42 + keyboardH;
const keyboardToolbarHeight = document.querySelector("#keyboardToolbar").clientHeight;
if (cellRect.bottom > keyboardToolbarHeight) {
contentElement.scrollTop = contentElement.scrollTop + (cellRect.bottom - keyboardToolbarHeight);
} else if (cellRect.top < 110) {
contentElement.scrollTop -= 110 - cellRect.top;
}

View file

@ -488,6 +488,17 @@ interface ISiyuan {
emojis?: IEmoji[],
backStack?: IBackStack[],
mobile?: {
size: {
isLandscape:boolean,
landscape: {
height1: number,
height2: number, // 键盘弹起时的高度
}, // 横屏
portrait: {
height1: number,
height2: number,
}
}
editor?: import("../protyle").Protyle
popEditor?: import("../protyle").Protyle
docks?: {