Skip to content

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

:bug: Keep mobile keyboard spacing outside table cells https://github.com/siyuan-note/siyuan/issues/19698

Daniel1e0045a63f01
diff --git a/app/src/mobile/util/keyboardToolbar.ts b/app/src/mobile/util/keyboardToolbar.ts
index 93ac477944..d32b83feae 100644
--- a/app/src/mobile/util/keyboardToolbar.ts
+++ b/app/src/mobile/util/keyboardToolbar.ts
@@ -9,7 +9,7 @@ import {moveToDown, moveToUp} from "../../protyle/wysiwyg/move";
import {Constants} from "../../constants";
import {focusBlock, focusByRange, getSelectionPosition} from "../../protyle/util/selection";
import {getCurrentEditor as getDocumentEditor} from "../editor";
-import {getMobileToolbarProtyle, getMobileToolbarUndo} from "../../protyle/lite/mobileToolbar";
+import {getMobileToolbarPaddingElement, getMobileToolbarProtyle, getMobileToolbarUndo} from "../../protyle/lite/mobileToolbar";
import {LocalUndo} from "../../protyle/undo";
import {convertFontSize, fontEvent, getFontNodeElements, getFontSizeInfo} from "../../protyle/toolbar/Font";
import {hideElements} from "../../protyle/ui/hideElements";
@@ -84,8 +84,6 @@ import {getKeyboardPanelHeight} from "./keyboardPanelHeight";
import {mountLiteSlashMenu} from "./liteSlashMenu";
const getCurrentEditor = () => getMobileToolbarProtyle()?.getInstance() || getDocumentEditor();
-const getKeyboardPaddingElement = (protyle: IProtyle) =>
- protyle.lite ? protyle.contentElement : protyle.element.parentElement;
let toolbarProtyle: IProtyle;
let unmountLiteSlashMenu: (() => void) | undefined;
@@ -426,7 +424,7 @@ const updateKeyboardPanelHeight = () => {
toolbarElement.style.height = panelHeight;
const editor = getCurrentEditor();
if (editor) {
- getKeyboardPaddingElement(editor.protyle).style.paddingBottom = panelHeight;
+ getMobileToolbarPaddingElement(editor.protyle).style.paddingBottom = panelHeight;
}
};
@@ -860,7 +858,7 @@ const hideKeyboardToolbarUtil = (restoreKeyboard = false) => {
updateKeyboardToolbarPosition();
const editor = getCurrentEditor();
if (editor) {
- getKeyboardPaddingElement(editor.protyle).style.paddingBottom = "48px";
+ getMobileToolbarPaddingElement(editor.protyle).style.paddingBottom = "48px";
}
resetKeyboardToolbarUtilButtons();
};
@@ -1075,7 +1073,7 @@ const showKeyboardToolbarElement = () => {
keyboardPanelClosing = false;
hideKeyboardToolbarUtil();
if (toolbarProtyle) {
- getKeyboardPaddingElement(toolbarProtyle).style.paddingBottom = "";
+ getMobileToolbarPaddingElement(toolbarProtyle).style.paddingBottom = "";
}
toolbarProtyle = protyle;
updateMobilePluginToolbar(protyle);
@@ -1098,7 +1096,7 @@ const showKeyboardToolbarElement = () => {
const editor = getCurrentEditor();
if (editor) {
if (editor.protyle.wysiwyg.element.contains(range.startContainer)) {
- getKeyboardPaddingElement(editor.protyle).style.paddingBottom = "48px";
+ getMobileToolbarPaddingElement(editor.protyle).style.paddingBottom = "48px";
}
forEachPluginSubscriber("mobile-keyboard-show", eventBus => {
eventBus.emit("mobile-keyboard-show");
@@ -1216,7 +1214,7 @@ export const hideKeyboardToolbar = () => {
toolbarElement.style.height = "";
const editor = getCurrentEditor();
if (editor) {
- getKeyboardPaddingElement(editor.protyle).style.paddingBottom = "";
+ getMobileToolbarPaddingElement(editor.protyle).style.paddingBottom = "";
if (!toolbarHidden) {
forEachPluginSubscriber("mobile-keyboard-hide", eventBus => {
eventBus.emit("mobile-keyboard-hide");
@@ -1286,7 +1284,7 @@ export const activeBlur = (force = false) => {
export const initKeyboardToolbar = () => {
window.addEventListener("siyuan-mobile-toolbar-editor", (event: CustomEvent<IProtyle>) => {
if (event.detail) {
- getKeyboardPaddingElement(event.detail).style.paddingBottom = "";
+ getMobileToolbarPaddingElement(event.detail).style.paddingBottom = "";
if (toolbarProtyle === event.detail) {
toolbarProtyle = undefined;
}
diff --git a/app/src/protyle/lite/mobileToolbar.test.ts b/app/src/protyle/lite/mobileToolbar.test.ts
index 018aeea0df..14804a29b3 100644
--- a/app/src/protyle/lite/mobileToolbar.test.ts
+++ b/app/src/protyle/lite/mobileToolbar.test.ts
@@ -1,6 +1,29 @@
import * as assert from "node:assert/strict";
import {test} from "node:test";
-import {bindMobileToolbar, getMobileToolbarProtyle, getMobileToolbarUndo, setMobileToolbarUndo} from "./mobileToolbar";
+import {bindMobileToolbar, getMobileToolbarPaddingElement, getMobileToolbarProtyle, getMobileToolbarUndo, setMobileToolbarUndo} from "./mobileToolbar";
+
+test("table cell keyboard padding belongs to its outer editor", () => {
+ const createEditor = (lite = false) => ({
+ lite,
+ element: {parentElement: {style: {paddingBottom: ""}}},
+ contentElement: {style: {paddingBottom: ""}},
+ }) as unknown as IProtyle;
+ for (const lite of [false, true]) {
+ const owner = createEditor(lite);
+ const cell = createEditor(true);
+ setMobileToolbarUndo(cell, owner, () => {});
+ const target = lite ? owner.contentElement : owner.element.parentElement;
+ assert.equal(getMobileToolbarPaddingElement(owner), target);
+ assert.equal(getMobileToolbarPaddingElement(cell), target);
+ for (const padding of ["48px", "320px", ""]) {
+ getMobileToolbarPaddingElement(cell).style.paddingBottom = padding;
+ assert.equal(target.style.paddingBottom, padding);
+ assert.equal(cell.contentElement.style.paddingBottom, "");
+ }
+ }
+ const composer = createEditor(true);
+ assert.equal(getMobileToolbarPaddingElement(composer), composer.contentElement);
+});
test("shared mobile toolbar follows fragment focus, retains panel ownership and releases destroyed editors", () => {
const originalWindow = Object.getOwnPropertyDescriptor(globalThis, "window");
diff --git a/app/src/protyle/lite/mobileToolbar.ts b/app/src/protyle/lite/mobileToolbar.ts
index e863c5b866..e3c07f4045 100644
--- a/app/src/protyle/lite/mobileToolbar.ts
+++ b/app/src/protyle/lite/mobileToolbar.ts
@@ -8,6 +8,12 @@ export const setMobileToolbarUndo = (protyle: IProtyle, owner: IProtyle, run: (r
export const getMobileToolbarUndo = (protyle: IProtyle) => undoContexts.get(protyle);
+export const getMobileToolbarPaddingElement = (protyle: IProtyle) => {
+ // 单元格的键盘占位放在所属编辑器上,避免撑高表格行。
+ const owner = undoContexts.get(protyle)?.owner || protyle;
+ return owner.lite ? owner.contentElement : owner.element.parentElement;
+};
+
export const getMobileToolbarProtyle = () => {
const root = document.activeElement?.closest(".protyle-wysiwyg");
if (root) {