Skip to content

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

:bug: Resize empty agent inputs within usable height bounds https://github.com/siyuan-note/siyuan/issues/20807

Daniel40980f0049ec
diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20230304000547-ibldj1z/20260804171004-aiagt03.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20230304000547-ibldj1z/20260804171004-aiagt03.sy
index fd6a7c4451..46cea5972c 100644
--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20230304000547-ibldj1z/20260804171004-aiagt03.sy
+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20230304000547-ibldj1z/20260804171004-aiagt03.sy
@@ -6,7 +6,7 @@
"id": "20260804171004-aiagt03",
"title": "AI Agent",
"type": "doc",
- "updated": "20261023005737"
+ "updated": "20261024153700"
},
"Children": [
{
@@ -275,7 +275,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20260804170027-iffmsq0",
- "updated": "20261016191345"
+ "updated": "20261024153700"
},
"Children": [
{
@@ -496,7 +496,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20260804170039-x813t3f",
- "updated": "20261023005737"
+ "updated": "20261024153700"
},
"Children": [
{
@@ -555,12 +555,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261022182404-71cve53",
- "updated": "20261023005737"
+ "updated": "20261024153700"
},
"Children": [
{
"Type": "NodeText",
- "Data": "The input grows automatically as you add text and images, then scrolls when it reaches its height limit. On desktop, hover over the input to reveal the small handle at the top; it remains visible on touch screens. Drag the handle upward or downward to adjust the limit. Double-click the handle to restore the automatic limit. Space above and below the content makes the first and last lines easier to inspect."
+ "Data": "The input grows automatically as you add text and images, then scrolls when it reaches its automatic height limit. On desktop, hover over the input to reveal the small handle at the top; it remains visible on touch screens. Drag the handle upward or downward to set a fixed height, even when the input is empty. The minimum height fits a complete line of text, and the maximum depends on the available panel space. Double-click the handle to restore automatic sizing. Space above and below the content makes the first and last lines easier to inspect."
}
]
},
@@ -569,7 +569,7 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261022182404-jbp15g8",
- "updated": "20261022182404"
+ "updated": "20261024153700"
},
"Children": [
{
@@ -592,7 +592,7 @@
},
{
"Type": "NodeText",
- "Data": " to increase or decrease the limit, "
+ "Data": " to increase or decrease the height, "
},
{
"Type": "NodeTextMark",
diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20230303235619-ex5l63e/20260804171000-aiagt01.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20230303235619-ex5l63e/20260804171000-aiagt01.sy
index 27a16a00c9..d6252730da 100644
--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20230303235619-ex5l63e/20260804171000-aiagt01.sy
+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20230303235619-ex5l63e/20260804171000-aiagt01.sy
@@ -6,7 +6,7 @@
"id": "20260804171000-aiagt01",
"title": "AI 智能体",
"type": "doc",
- "updated": "20261023005737"
+ "updated": "20261024153700"
},
"Children": [
{
@@ -275,7 +275,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20260804170027-76js6ua",
- "updated": "20261016191345"
+ "updated": "20261024153700"
},
"Children": [
{
@@ -496,7 +496,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20260804170039-6hkjcgx",
- "updated": "20261023005737"
+ "updated": "20261024153700"
},
"Children": [
{
@@ -555,12 +555,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261022182404-g6vs2ax",
- "updated": "20261023005737"
+ "updated": "20261024153700"
},
"Children": [
{
"Type": "NodeText",
- "Data": "输入框随文字和图片自动增高,达到高度上限后滚动。桌面端将鼠标移入输入区域后显示顶部的小把手,触屏设备上保持显示。向上或向下拖动把手可调整上限,双击把手可恢复自动上限。内容首尾保留滚动余量,便于完整查看首行和末行。"
+ "Data": "输入框默认随文字和图片自动增高,达到自动高度上限后滚动。桌面端将鼠标移入输入区域后显示顶部的小把手,触屏设备上保持显示。拖动把手可在允许范围内设置固定高度,空输入框也能拉高;最小高度可完整容纳一行文本,最大高度受面板可用空间限制。双击把手可恢复自动增高。内容首尾保留滚动余量,便于完整查看首行和末行。"
}
]
},
@@ -569,7 +569,7 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261022182404-hm91uco",
- "updated": "20261022182404"
+ "updated": "20261024153700"
},
"Children": [
{
@@ -592,7 +592,7 @@
},
{
"Type": "NodeText",
- "Data": " 增大或减小上限,按 "
+ "Data": " 增大或减小高度,按 "
},
{
"Type": "NodeTextMark",
diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20230304000829-9jwu3po/20260804171002-aiagt02.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20230304000829-9jwu3po/20260804171002-aiagt02.sy
index d520b8c902..fde3edbf7e 100644
--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20230304000829-9jwu3po/20260804171002-aiagt02.sy
+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20230304000829-9jwu3po/20260804171002-aiagt02.sy
@@ -6,7 +6,7 @@
"id": "20260804171002-aiagt02",
"title": "AI 智能體",
"type": "doc",
- "updated": "20261023005737"
+ "updated": "20261024153700"
},
"Children": [
{
@@ -275,7 +275,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20260804170027-qlngedh",
- "updated": "20261016191345"
+ "updated": "20261024153700"
},
"Children": [
{
@@ -496,7 +496,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20260804170039-1z57i1s",
- "updated": "20261023005737"
+ "updated": "20261024153700"
},
"Children": [
{
@@ -555,12 +555,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261022182404-zoui51x",
- "updated": "20261023005737"
+ "updated": "20261024153700"
},
"Children": [
{
"Type": "NodeText",
- "Data": "輸入框會隨文字和圖片自動增高,達到高度上限後捲動。桌面端將滑鼠移入輸入區域後會顯示頂部的小控制點,觸控裝置上則保持顯示。向上或向下拖曳控制點可調整上限,按兩下控制點可恢復自動上限。內容首尾保留捲動空間,方便完整查看首行和末行。"
+ "Data": "輸入框預設會隨文字和圖片自動增高,達到自動高度上限後捲動。桌面端將滑鼠移入輸入區域後會顯示頂部的小控制點,觸控裝置上則保持顯示。拖曳控制點可在允許範圍內設定固定高度,空白輸入框也能拉高;最小高度可完整容納一行文字,最大高度受面板可用空間限制。按兩下控制點可恢復自動增高。內容首尾保留捲動空間,方便完整查看首行和末行。"
}
]
},
@@ -569,7 +569,7 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261022182404-72jon51",
- "updated": "20261022182404"
+ "updated": "20261024153700"
},
"Children": [
{
@@ -592,7 +592,7 @@
},
{
"Type": "NodeText",
- "Data": " 增大或減小上限,按 "
+ "Data": " 增大或減小高度,按 "
},
{
"Type": "NodeTextMark",
diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-ei5t6tt/20260804171006-aiagt04.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-ei5t6tt/20260804171006-aiagt04.sy
index 7cfd989c2a..5298353103 100644
--- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-ei5t6tt/20260804171006-aiagt04.sy
+++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-ei5t6tt/20260804171006-aiagt04.sy
@@ -6,7 +6,7 @@
"id": "20260804171006-aiagt04",
"title": "AI エージェント",
"type": "doc",
- "updated": "20261023005737"
+ "updated": "20261024153700"
},
"Children": [
{
@@ -267,7 +267,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20260804170027-2jaadkf",
- "updated": "20261016191953"
+ "updated": "20261024153700"
},
"Children": [
{
@@ -488,7 +488,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20260804170039-9kcdqv4",
- "updated": "20261023005737"
+ "updated": "20261024153700"
},
"Children": [
{
@@ -547,12 +547,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261022182404-hxp98ok",
- "updated": "20261023005737"
+ "updated": "20261024153700"
},
"Children": [
{
"Type": "NodeText",
- "Data": "入力欄は文字や画像に合わせて自動的に高くなり、上限に達するとスクロールします。デスクトップでは入力欄にマウスポインターを合わせると上端に小さなハンドルが表示され、タッチ画面では常に表示されます。ハンドルを上下にドラッグすると上限を調整できます。ハンドルをダブルクリックすると自動の上限に戻ります。内容の前後にはスクロール用の余白があり、最初と最後の行を確認しやすくなっています。"
+ "Data": "入力欄は文字や画像に合わせて自動的に高くなり、自動調整の上限に達するとスクロールします。デスクトップでは入力欄にマウスポインターを合わせると上端に小さなハンドルが表示され、タッチ画面では常に表示されます。ハンドルを上下にドラッグすると、許容範囲内で高さを固定でき、空の入力欄も広げられます。最小の高さはテキストを一行すべて表示できる大きさで、最大の高さはパネルの利用可能なスペースに応じて決まります。ハンドルをダブルクリックすると自動調整に戻ります。内容の前後にはスクロール用の余白があり、最初と最後の行を確認しやすくなっています。"
}
]
},
@@ -561,7 +561,7 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261022182404-yecrc0p",
- "updated": "20261022182404"
+ "updated": "20261024153700"
},
"Children": [
{
@@ -584,7 +584,7 @@
},
{
"Type": "NodeText",
- "Data": " で上限を増減し、"
+ "Data": " で高さを増減し、"
},
{
"Type": "NodeTextMark",
diff --git a/app/src/assets/scss/business/_ai_agent.scss b/app/src/assets/scss/business/_ai_agent.scss
index 500dc06f35..eae32fe840 100644
--- a/app/src/assets/scss/business/_ai_agent.scss
+++ b/app/src/assets/scss/business/_ai_agent.scss
@@ -705,14 +705,15 @@
}
.agent-chat__composer-host {
- min-height: 40px;
+ // 一行正文、段落边距与上下滚动留白。
+ min-height: calc(var(--b3-font-size) * 1.625 + 44px);
max-height: min(240px, 40vh);
overflow: hidden;
cursor: text;
.protyle-content {
min-height: 0;
- flex: 0 1 auto;
+ flex: 1 1 auto;
padding: 8px 0 24px;
scroll-padding-block: 8px 24px;
box-sizing: border-box;
diff --git a/app/src/layout/dock/agent/AgentComposerResize.test.ts b/app/src/layout/dock/agent/AgentComposerResize.test.ts
index fe13fcbcd4..426a01d8b6 100644
--- a/app/src/layout/dock/agent/AgentComposerResize.test.ts
+++ b/app/src/layout/dock/agent/AgentComposerResize.test.ts
@@ -17,12 +17,13 @@ const cases = async (source: string, css: string, mobile: boolean) => {
document.body.innerHTML = `<div class="sy__agentChat fn__flex-column file-tree dockPanel${mobile ? " sy__agentChat--mobile" : ""}" ` +
'style="width:360px;height:760px;min-height:0;box-sizing:border-box">' +
'<div class="block__icons" style="height:48px">Agent</div>' +
+ '<div class="agent-chat fn__flex-column fn__flex-1">' +
'<div class="agent-chat__messages-wrap"><div class="agent-chat__messages">Messages</div></div>' +
'<div class="agent-chat__input-area"><div class="agent-chat__input-resize" data-prevent-swipe="true">' +
'<span class="protyle-block-resize" data-resize-axis="height" tabindex="0" role="separator"></span></div>' +
'<div class="agent-chat__composer-host protyle protyle-lite-fragment" data-protyle-lite="true">' +
'<div class="protyle-content"><div class="protyle-wysiwyg" spellcheck="false"></div></div></div>' +
- '<div class="agent-chat__buttons"><button class="b3-button">Send</button></div></div></div>';
+ '<div class="agent-chat__buttons"><button class="b3-button">Send</button></div></div></div></div>';
const panel = document.querySelector<HTMLElement>(".sy__agentChat");
// 原生窗口可能受运行器屏幕尺寸限制,面板必须完全位于实际视口内。
const panelHeight = Math.min(760, window.innerHeight);
@@ -37,6 +38,14 @@ const cases = async (source: string, css: string, mobile: boolean) => {
await tick();
};
const moveMouse = (x: number, y: number) => input("Input.dispatchMouseEvent", {type: "mouseMoved", x, y});
+ const dragBy = async (dy: number, options: {touch?: boolean, touchEnd?: boolean, escape?: boolean} = {}) => {
+ const rect = handle.getBoundingClientRect();
+ await require("electron").ipcRenderer.invoke("composer-drag", {
+ x: Math.round(rect.left + rect.width / 2), y: Math.round(rect.top + rect.height / 2), dy, ...options,
+ });
+ await tick();
+ };
+ const key = (name: string) => handle.dispatchEvent(new KeyboardEvent("keydown", {key: name, bubbles: true, cancelable: true}));
const paragraph = (text: string) => '<div class="p" data-node-id="20261022000000-abcdefg" data-type="NodeParagraph">' +
`<div contenteditable="true" spellcheck="false">${text}</div></div>`;
const short = () => editor.innerHTML = paragraph("Short input");
@@ -62,6 +71,52 @@ const cases = async (source: string, css: string, mobile: boolean) => {
check.equal(matchMedia("(hover: none) and (pointer: coarse)").matches, true);
check.equal(getComputedStyle(handle).opacity, "1", "touch devices retain a visible handle without hover");
await input("Emulation.setTouchEmulationEnabled", {enabled: false});
+ editor.innerHTML = paragraph("");
+ await tick();
+ const emptyHeight = composer.clientHeight;
+ await dragBy(-120);
+ check.equal(composer.clientHeight, emptyHeight + 120, "dragging an empty composer sets its actual height");
+ check.equal(content.clientHeight, composer.clientHeight, "the editable scroll area fills a manually enlarged composer");
+ const maximum = handle.getAttribute("aria-valuemax");
+ await dragBy(-1000);
+ check.equal(composer.clientHeight, Number(maximum), "dragging stops at the upper bound");
+ await dragBy(-100);
+ check.equal(composer.clientHeight, Number(maximum), "repeated drags cannot increase the upper bound");
+ check.equal(handle.getAttribute("aria-valuemax"), maximum);
+ await dragBy(Number(maximum) - emptyHeight - 120);
+ short();
+ await tick();
+ check.equal(composer.clientHeight, emptyHeight + 120, "typing one line preserves the chosen height");
+ await dragBy(1000);
+ check.equal(content.scrollHeight, content.clientHeight, "shrinking a single line does not create a scrollbar");
+ check.equal(composer.clientHeight, Number(handle.getAttribute("aria-valuemin")), "dragging stops at the minimum height");
+ for (const fontSize of [16, 32]) {
+ panel.style.setProperty("--b3-font-size", `${fontSize}px`);
+ for (const text of ["", "Short input"]) {
+ editor.innerHTML = paragraph(text);
+ await tick();
+ key("Home");
+ await tick();
+ check.equal(content.scrollHeight, content.clientHeight, `minimum height fits one line at ${fontSize}px`);
+ check.equal(composer.clientHeight, Number(handle.getAttribute("aria-valuemin")));
+ }
+ }
+ panel.style.removeProperty("--b3-font-size");
+ handle.dispatchEvent(new MouseEvent("dblclick", {bubbles: true}));
+ await tick();
+ check.equal(composer.style.height, "", "double click restores automatic sizing after resizing empty content");
+ await dragBy(-100, {escape: true});
+ check.equal(composer.style.height, "", "canceling the first drag restores automatic sizing");
+ await dragBy(-100, {touch: true});
+ check.equal(composer.style.height, "", "canceling a touch drag restores automatic sizing");
+ const automaticHeight = composer.clientHeight;
+ key("ArrowUp");
+ check.equal(composer.clientHeight, automaticHeight + 24, "keyboard resizing starts from the visible height");
+ key("Home");
+ const touchHeight = composer.clientHeight;
+ await dragBy(-100, {touch: true, touchEnd: true});
+ check.equal(composer.clientHeight, touchHeight + 100, "touch dragging sets the height even with one line");
+ handle.dispatchEvent(new MouseEvent("dblclick", {bubbles: true}));
const image = '<span class="img"><span></span><span><img alt="Image" ' +
'src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"></span></span>';
editor.innerHTML = paragraph(image) + paragraph("After image") + paragraph("Last line");
@@ -81,7 +136,6 @@ const cases = async (source: string, css: string, mobile: boolean) => {
content.scrollTop = 0;
check.ok(editor.firstElementChild.getBoundingClientRect().top - content.getBoundingClientRect().top >= 7);
- const key = (name: string) => handle.dispatchEvent(new KeyboardEvent("keydown", {key: name, bubbles: true, cancelable: true}));
handle.focus();
key("ArrowUp");
check.equal(composer.style.maxHeight, "264px");
@@ -102,13 +156,13 @@ const cases = async (source: string, css: string, mobile: boolean) => {
const x = Math.round(rect.left + rect.width / 2);
const y = Math.round(rect.top + rect.height / 2);
await require("electron").ipcRenderer.invoke("composer-drag", {x, y, dy: -100, touch: false});
- check.ok(composer.clientHeight >= 338 && composer.clientHeight <= 342, "mouse dragging raises the height cap");
+ check.ok(composer.clientHeight >= 338 && composer.clientHeight <= 342, "mouse dragging raises the actual height");
check.equal(handle.classList.contains("touch-resize-active"), false);
check.equal(document.activeElement, editable, "mouse dragging keeps focus in the composer");
check.equal(getComputedStyle(handle).outlineStyle, "none", "mouse dragging does not leave a keyboard focus box");
await moveMouse(900, 10);
check.equal(getComputedStyle(handle).opacity, "0", "the handle hides after dragging and leaving the input");
- const preferred = composer.style.maxHeight;
+ const preferred = composer.style.height;
const escapeRect = handle.getBoundingClientRect();
let escapedEditor = false;
editable.addEventListener("keydown", event => escapedEditor ||= event.key === "Escape");
@@ -116,7 +170,7 @@ const cases = async (source: string, css: string, mobile: boolean) => {
x: Math.round(escapeRect.left + escapeRect.width / 2), y: Math.round(escapeRect.top + escapeRect.height / 2),
dy: -50, touch: false, escape: true,
});
- check.equal(composer.style.maxHeight, preferred, "Escape cancels dragging while focus stays in the editor");
+ check.equal(composer.style.height, preferred, "Escape cancels dragging while focus stays in the editor");
check.equal(escapedEditor, false, "canceling a drag does not trigger editor Escape actions");
check.equal(handle.classList.contains("touch-resize-active"), false);
const touchRect = handle.getBoundingClientRect();
@@ -124,7 +178,7 @@ const cases = async (source: string, css: string, mobile: boolean) => {
x: Math.round(touchRect.left + touchRect.width / 2), y: Math.round(touchRect.top + touchRect.height / 2),
dy: -50, touch: true,
});
- check.equal(composer.style.maxHeight, preferred, "touch cancellation restores the previous cap");
+ check.equal(composer.style.height, preferred, "touch cancellation restores the previous height");
check.equal(handle.classList.contains("touch-resize-active"), false);
for (const fontSize of [16, 32]) {
@@ -133,7 +187,7 @@ const cases = async (source: string, css: string, mobile: boolean) => {
panel.style.width = `${width}px`;
panel.style.height = "400px";
await tick();
- check.equal(composer.style.maxHeight, "240px", "smaller panels clamp an expanded composer");
+ check.equal(composer.style.height, "240px", "smaller panels clamp an expanded composer");
check.ok(panel.querySelector(".agent-chat__buttons").getBoundingClientRect().bottom <= panel.getBoundingClientRect().bottom + 1);
check.ok(content.clientWidth <= composer.clientWidth);
content.scrollTop = content.scrollHeight;
@@ -143,33 +197,39 @@ const cases = async (source: string, css: string, mobile: boolean) => {
panel.style.height = "760px";
panel.style.paddingBottom = "400px";
await tick();
- check.equal(composer.style.maxHeight, "200px", "mobile keyboard padding reduces available content height");
+ check.equal(composer.style.height, "200px", "mobile keyboard padding reduces available content height");
panel.style.paddingBottom = "0";
await tick();
- check.equal(composer.style.maxHeight, preferred, "reopening the available space restores the chosen cap");
+ check.equal(composer.style.height, preferred, "reopening the available space restores the chosen height");
short();
await tick();
- check.ok(composer.clientHeight < 120, "clearing long content returns to intrinsic height");
+ check.equal(composer.style.height, preferred, "clearing long content retains a manually chosen height");
+ check.equal(composer.clientHeight, parseFloat(preferred));
const clickRect = handle.getBoundingClientRect();
await require("electron").ipcRenderer.invoke("composer-drag", {
x: Math.round(clickRect.left + clickRect.width / 2), y: Math.round(clickRect.top + clickRect.height / 2),
dy: 0, touch: false,
});
- check.equal(composer.style.maxHeight, preferred, "clicking without dragging does not shrink the automatic growth limit");
+ check.equal(composer.style.height, preferred, "clicking without dragging does not change the chosen height");
handle.dispatchEvent(new MouseEvent("dblclick", {bubbles: true}));
check.equal(composer.style.maxHeight, "240px", "double click restores the automatic cap");
+ await tick();
+ check.ok(composer.clientHeight < 120, "resetting returns short content to intrinsic height");
long();
await tick();
+ key("End");
+ check.notEqual(composer.style.height, "");
destroy();
key("End");
check.equal(composer.style.maxHeight, "", "destroy removes listeners and the temporary geometry");
+ check.equal(composer.style.height, "");
const escape = new KeyboardEvent("keydown", {key: "Escape", bubbles: true, cancelable: true});
panel.dispatchEvent(escape);
check.equal(escape.defaultPrevented, false, "Escape is not intercepted after disposal");
return "Composer resize and scrolling passed";
};
-test("composer grows, resizes and preserves focus, handle visibility and scroll space on desktop and mobile", {
+test("composer preserves automatic growth and bounded manual heights on desktop and mobile", {
skip: process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY,
timeout: 60000,
}, async () => {
@@ -188,7 +248,7 @@ app.whenReady().then(async () => {
webPreferences: {nodeIntegration: true, contextIsolation: false, offscreen: true, backgroundThrottling: false}});
win.webContents.debugger.attach("1.3");
ipcMain.handle("composer-input", (_event, method, params) => win.webContents.debugger.sendCommand(method, params));
- ipcMain.handle("composer-drag", async (_event, {x, y, dy, touch, escape}) => {
+ ipcMain.handle("composer-drag", async (_event, {x, y, dy, touch, touchEnd, escape}) => {
const send = async (method, params) => {
await win.webContents.debugger.sendCommand(method, params);
await new Promise(resolve => setTimeout(resolve, 40));
@@ -197,7 +257,7 @@ app.whenReady().then(async () => {
await send("Emulation.setTouchEmulationEnabled", {enabled: true});
await send("Input.dispatchTouchEvent", {type: "touchStart", touchPoints: [{x, y}]});
await send("Input.dispatchTouchEvent", {type: "touchMove", touchPoints: [{x, y: y + dy}]});
- await send("Input.dispatchTouchEvent", {type: "touchCancel", touchPoints: []});
+ await send("Input.dispatchTouchEvent", {type: touchEnd ? "touchEnd" : "touchCancel", touchPoints: []});
await send("Emulation.setTouchEmulationEnabled", {enabled: false});
} else {
await send("Input.dispatchMouseEvent", {type: "mousePressed", x, y, button: "left", buttons: 1, clickCount: 1});
diff --git a/app/src/layout/dock/agent/AgentComposerResize.ts b/app/src/layout/dock/agent/AgentComposerResize.ts
index f1db35ff4b..b4e1b65800 100644
--- a/app/src/layout/dock/agent/AgentComposerResize.ts
+++ b/app/src/layout/dock/agent/AgentComposerResize.ts
@@ -1,7 +1,8 @@
-// 上方把手调节输入框的最大高度,正文仍按实际内容自动增高或收缩。
+// 输入框默认随内容增高;手动调节后保持所选高度,双击把手恢复自动尺寸。
export const bindAgentComposerResize = (panel: HTMLElement, composer: HTMLElement, handle: HTMLElement) => {
const windowSelf = panel.ownerDocument.defaultView;
let preferred: number | undefined;
+ let minimum = 40;
let maximum = 240;
let value = 240;
let drag: {id: number, y: number, height: number, previous?: number, moved?: boolean} | undefined;
@@ -9,14 +10,17 @@ export const bindAgentComposerResize = (panel: HTMLElement, composer: HTMLElemen
const style = windowSelf.getComputedStyle(panel);
const height = Math.min(panel.clientHeight - parseFloat(style.paddingTop) - parseFloat(style.paddingBottom),
windowSelf.visualViewport?.height || windowSelf.innerHeight);
- if (!height) {
+ if (height <= 0) {
return;
}
+ minimum = Math.max(40, Math.ceil(parseFloat(windowSelf.getComputedStyle(composer).minHeight)) || 0);
// 给标题、操作栏和会话正文留出空间,软键盘弹出时也不能把发送按钮挤出面板。
- maximum = Math.max(40, Math.floor(height - 160));
- value = Math.round(Math.max(40, Math.min(maximum, preferred ?? Math.min(240, height * .4))));
- composer.style.maxHeight = `${value}px`;
- handle.setAttribute("aria-valuemin", "40");
+ maximum = Math.max(minimum, Math.floor(height - 160));
+ const limit = Math.round(Math.max(minimum, Math.min(maximum, preferred ?? Math.min(240, height * .4))));
+ composer.style.maxHeight = `${limit}px`;
+ composer.style.height = preferred === undefined ? "" : `${limit}px`;
+ value = composer.clientHeight;
+ handle.setAttribute("aria-valuemin", String(minimum));
handle.setAttribute("aria-valuemax", String(maximum));
handle.setAttribute("aria-valuenow", String(value));
};
@@ -41,6 +45,7 @@ export const bindAgentComposerResize = (panel: HTMLElement, composer: HTMLElemen
}
event.preventDefault();
event.stopPropagation();
+ update();
drag = {id: event.pointerId, y: event.clientY, height: composer.clientHeight, previous: preferred};
handle.setPointerCapture(event.pointerId);
handle.classList.add("touch-resize-active");
@@ -54,7 +59,7 @@ export const bindAgentComposerResize = (panel: HTMLElement, composer: HTMLElemen
}
event.preventDefault();
drag.moved = true;
- preferred = Math.max(40, Math.min(maximum, drag.height + drag.y - event.clientY));
+ preferred = Math.max(minimum, Math.min(maximum, drag.height + drag.y - event.clientY));
update();
};
const up = (event: PointerEvent) => {
@@ -72,11 +77,12 @@ export const bindAgentComposerResize = (panel: HTMLElement, composer: HTMLElemen
}
};
const keydown = (event: KeyboardEvent) => {
+ update();
if (event.key === "ArrowUp" || event.key === "ArrowDown") {
- preferred = Math.max(40, Math.min(maximum, value + (event.key === "ArrowUp" ? 24 : -24)));
+ preferred = Math.max(minimum, Math.min(maximum, value + (event.key === "ArrowUp" ? 24 : -24)));
update();
} else if (event.key === "Home" || event.key === "End") {
- preferred = event.key === "Home" ? 40 : maximum;
+ preferred = event.key === "Home" ? minimum : maximum;
update();
} else {
return;
@@ -102,6 +108,7 @@ export const bindAgentComposerResize = (panel: HTMLElement, composer: HTMLElemen
windowSelf.visualViewport?.addEventListener("resize", update);
const observer = new ResizeObserver(update);
observer.observe(panel);
+ observer.observe(composer);
update();
return () => {
finish(true);
@@ -118,5 +125,6 @@ export const bindAgentComposerResize = (panel: HTMLElement, composer: HTMLElemen
windowSelf.removeEventListener("resize", update);
windowSelf.visualViewport?.removeEventListener("resize", update);
composer.style.maxHeight = "";
+ composer.style.height = "";
};
};