Skip to content

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

:bug: Keep the mobile agent composer above insert panels https://github.com/siyuan-note/siyuan/issues/19696

Daniel9f6e2a33925d
diff --git a/app/src/assets/scss/business/_ai_agent.scss b/app/src/assets/scss/business/_ai_agent.scss
index fb7580553b..330abed410 100644
--- a/app/src/assets/scss/business/_ai_agent.scss
+++ b/app/src/assets/scss/business/_ai_agent.scss
@@ -1257,6 +1257,7 @@
.sy__agentChat--mobile {
position: relative;
+ box-sizing: border-box;
height: 100%;
min-height: 0;
background: var(--b3-theme-background);
diff --git a/app/src/mobile/util/liteSlashMenu.test.ts b/app/src/mobile/util/liteSlashMenu.test.ts
index d4a9c4fcea..cb43263fa6 100644
--- a/app/src/mobile/util/liteSlashMenu.test.ts
+++ b/app/src/mobile/util/liteSlashMenu.test.ts
@@ -9,10 +9,11 @@ import {createSourceFile, isClassDeclaration, isMethodDeclaration, ScriptTarget,
const browserCases = async (source: string, hintSource: string) => {
const check: typeof assert = require("node:assert/strict");
- const {mount, render} = new Function(source + hintSource +
- "\nreturn {mount: mountLiteSlashMenu, render: Hint.prototype.getHTMLByData};")() as {
+ const {mount, render, paddingElement} = new Function(source + hintSource +
+ "\nreturn {mount: mountLiteSlashMenu, render: Hint.prototype.getHTMLByData, paddingElement: getMobileToolbarPaddingElement};")() as {
mount: typeof import("./liteSlashMenu").mountLiteSlashMenu,
render: (data: IHintData[]) => string,
+ paddingElement: typeof import("../../protyle/lite/mobileToolbar").getMobileToolbarPaddingElement,
};
window.siyuan = {languages: {emptyContent: "Empty"}} as unknown as typeof window.siyuan;
const element = document.createElement("div");
@@ -106,6 +107,35 @@ const browserCases = async (source: string, hintSource: string) => {
provider.hint = () => items;
mount(protyle, panel);
toolbar.style.width = "390px";
+
+ const agent = document.createElement("div");
+ agent.className = "sy__agentChat sy__agentChat--mobile fn__flex-column";
+ agent.style.position = "fixed";
+ agent.style.top = "0";
+ agent.innerHTML = '<div class="block__icons">Agent</div><div class="agent-chat fn__flex-column fn__flex-1">' +
+ '<div class="agent-chat__messages-wrap"><div class="agent-chat__messages fn__flex-1">Messages</div></div>' +
+ '<div class="agent-chat__input-area"><div class="agent-chat__composer-host">' +
+ '<div class="protyle-content"><div contenteditable="true">Input</div></div></div>' +
+ '<div class="agent-chat__buttons"><button class="b3-button">Send</button></div></div></div>';
+ document.body.appendChild(agent);
+ const contentElement = agent.querySelector<HTMLElement>(".protyle-content");
+ const composer = {lite: true, element: contentElement.parentElement, contentElement} as IProtyle;
+ for (const width of [320, 390, 768]) {
+ agent.style.width = `${width}px`;
+ for (const fontSize of [16, 32]) {
+ agent.style.fontSize = `${fontSize}px`;
+ for (const [height, padding] of [[700, 350], [420, 48], [700, 0]]) {
+ agent.style.height = `${height}px`;
+ paddingElement(composer).style.paddingBottom = padding ? `${padding}px` : "";
+ const input = agent.querySelector(".agent-chat__input-area").getBoundingClientRect();
+ check.ok(input.bottom <= height - padding, "composer stays above the keyboard panel");
+ check.ok(input.top >= agent.querySelector(".block__icons").getBoundingClientRect().bottom);
+ check.equal(contentElement.style.paddingBottom, "");
+ check.equal(agent.getBoundingClientRect().height, height, "padding does not enlarge the page");
+ }
+ }
+ }
+ agent.remove();
return "Mobile slash cases passed";
};
@@ -113,7 +143,8 @@ test("mobile slash panel retains synchronous and asynchronous candidates and rel
skip: process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY,
timeout: 45000,
}, async () => {
- const source = transpileModule(readFileSync(path.join(__dirname, "liteSlashMenu.ts"), "utf8")
+ const source = transpileModule((readFileSync(path.join(__dirname, "liteSlashMenu.ts"), "utf8") + "\n" +
+ readFileSync(path.join(__dirname, "../../protyle/lite/mobileToolbar.ts"), "utf8"))
.replace(/^export /gm, ""), {compilerOptions: {target: ScriptTarget.ES2021}}).outputText;
const hintFile = createSourceFile("hint.ts", readFileSync(path.join(__dirname, "../../protyle/hint/index.ts"), "utf8"),
ScriptTarget.Latest, true);
diff --git a/app/src/protyle/lite/mobileToolbar.test.ts b/app/src/protyle/lite/mobileToolbar.test.ts
index 14804a29b3..74c7568df1 100644
--- a/app/src/protyle/lite/mobileToolbar.test.ts
+++ b/app/src/protyle/lite/mobileToolbar.test.ts
@@ -5,7 +5,7 @@ import {bindMobileToolbar, getMobileToolbarPaddingElement, getMobileToolbarProty
test("table cell keyboard padding belongs to its outer editor", () => {
const createEditor = (lite = false) => ({
lite,
- element: {parentElement: {style: {paddingBottom: ""}}},
+ element: {parentElement: {style: {paddingBottom: ""}}, closest: (): unknown => null},
contentElement: {style: {paddingBottom: ""}},
}) as unknown as IProtyle;
for (const lite of [false, true]) {
@@ -23,6 +23,19 @@ test("table cell keyboard padding belongs to its outer editor", () => {
}
const composer = createEditor(true);
assert.equal(getMobileToolbarPaddingElement(composer), composer.contentElement);
+ const agentPanel = {style: {paddingBottom: ""}};
+ composer.element.closest = (() => agentPanel) as typeof composer.element.closest;
+ const cell = createEditor(true);
+ setMobileToolbarUndo(cell, composer, () => {});
+ for (const editor of [composer, cell]) {
+ assert.equal(getMobileToolbarPaddingElement(editor), agentPanel);
+ for (const padding of ["48px", "320px", ""]) {
+ getMobileToolbarPaddingElement(editor).style.paddingBottom = padding;
+ assert.equal(agentPanel.style.paddingBottom, padding);
+ assert.equal(composer.contentElement.style.paddingBottom, "");
+ assert.equal(cell.contentElement.style.paddingBottom, "");
+ }
+ }
});
test("shared mobile toolbar follows fragment focus, retains panel ownership and releases destroyed editors", () => {
diff --git a/app/src/protyle/lite/mobileToolbar.ts b/app/src/protyle/lite/mobileToolbar.ts
index e3c07f4045..a9f8c731fc 100644
--- a/app/src/protyle/lite/mobileToolbar.ts
+++ b/app/src/protyle/lite/mobileToolbar.ts
@@ -11,6 +11,11 @@ export const getMobileToolbarUndo = (protyle: IProtyle) => undoContexts.get(prot
export const getMobileToolbarPaddingElement = (protyle: IProtyle) => {
// 单元格的键盘占位放在所属编辑器上,避免撑高表格行。
const owner = undoContexts.get(protyle)?.owner || protyle;
+ // 智能体输入框有高度上限,键盘占位由整个页面承担,保持输入区位于面板上方。
+ const agentPanel = owner.element.closest<HTMLElement>(".sy__agentChat--mobile");
+ if (agentPanel) {
+ return agentPanel;
+ }
return owner.lite ? owner.contentElement : owner.element.parentElement;
};