Skip to content

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

:bug: Preserve composer focus and reveal resize handle on hover https://github.com/siyuan-note/siyuan/issues/20807

Danielfe66cf4eddda
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 86b98cb3c6..fd6a7c4451 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": "20261022182404"
+ "updated": "20261023005737"
},
"Children": [
{
@@ -496,7 +496,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20260804170039-x813t3f",
- "updated": "20261022182404"
+ "updated": "20261023005737"
},
"Children": [
{
@@ -555,12 +555,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261022182404-71cve53",
- "updated": "20261022182404"
+ "updated": "20261023005737"
},
"Children": [
{
"Type": "NodeText",
- "Data": "The input grows automatically as you add text and images, then scrolls when it reaches its height limit. Drag the small handle at the top upward or downward to adjust that limit; touch screens support the same gesture. 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 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."
}
]
},
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 148e397f82..27a16a00c9 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": "20261022182404"
+ "updated": "20261023005737"
},
"Children": [
{
@@ -496,7 +496,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20260804170039-6hkjcgx",
- "updated": "20261022182404"
+ "updated": "20261023005737"
},
"Children": [
{
@@ -555,12 +555,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261022182404-g6vs2ax",
- "updated": "20261022182404"
+ "updated": "20261023005737"
},
"Children": [
{
"Type": "NodeText",
- "Data": "输入框随文字和图片自动增高,达到高度上限后滚动。向上或向下拖动输入框顶部的小把手可调整上限,触摸屏也支持拖动;双击把手可恢复自动上限。内容首尾保留滚动余量,便于完整查看首行和末行。"
+ "Data": "输入框随文字和图片自动增高,达到高度上限后滚动。桌面端将鼠标移入输入区域后显示顶部的小把手,触屏设备上保持显示。向上或向下拖动把手可调整上限,双击把手可恢复自动上限。内容首尾保留滚动余量,便于完整查看首行和末行。"
}
]
},
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 318d717cf2..d520b8c902 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": "20261022182404"
+ "updated": "20261023005737"
},
"Children": [
{
@@ -496,7 +496,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20260804170039-1z57i1s",
- "updated": "20261022182404"
+ "updated": "20261023005737"
},
"Children": [
{
@@ -555,12 +555,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261022182404-zoui51x",
- "updated": "20261022182404"
+ "updated": "20261023005737"
},
"Children": [
{
"Type": "NodeText",
- "Data": "輸入框會隨文字和圖片自動增高,達到高度上限後捲動。向上或向下拖曳輸入框頂部的小控制點可調整上限,觸控螢幕也支援拖曳;按兩下控制點可恢復自動上限。內容首尾保留捲動空間,方便完整查看首行和末行。"
+ "Data": "輸入框會隨文字和圖片自動增高,達到高度上限後捲動。桌面端將滑鼠移入輸入區域後會顯示頂部的小控制點,觸控裝置上則保持顯示。向上或向下拖曳控制點可調整上限,按兩下控制點可恢復自動上限。內容首尾保留捲動空間,方便完整查看首行和末行。"
}
]
},
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 6fb1907597..7cfd989c2a 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": "20261022182404"
+ "updated": "20261023005737"
},
"Children": [
{
@@ -488,7 +488,7 @@
"HeadingLevel": 3,
"Properties": {
"id": "20260804170039-9kcdqv4",
- "updated": "20261022182404"
+ "updated": "20261023005737"
},
"Children": [
{
@@ -547,12 +547,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261022182404-hxp98ok",
- "updated": "20261022182404"
+ "updated": "20261023005737"
},
"Children": [
{
"Type": "NodeText",
- "Data": "入力欄は文字や画像に合わせて自動的に高くなり、上限に達するとスクロールします。入力欄の上端にある小さなハンドルを上下にドラッグすると上限を調整できます。タッチ画面でも同じ操作が可能です。ハンドルをダブルクリックすると自動の上限に戻ります。内容の前後にはスクロール用の余白があり、最初と最後の行を確認しやすくなっています。"
+ "Data": "入力欄は文字や画像に合わせて自動的に高くなり、上限に達するとスクロールします。デスクトップでは入力欄にマウスポインターを合わせると上端に小さなハンドルが表示され、タッチ画面では常に表示されます。ハンドルを上下にドラッグすると上限を調整できます。ハンドルをダブルクリックすると自動の上限に戻ります。内容の前後にはスクロール用の余白があり、最初と最後の行を確認しやすくなっています。"
}
]
},
diff --git a/app/src/assets/scss/business/_ai_agent.scss b/app/src/assets/scss/business/_ai_agent.scss
index 4f39ddbb77..cfb925a22f 100644
--- a/app/src/assets/scss/business/_ai_agent.scss
+++ b/app/src/assets/scss/business/_ai_agent.scss
@@ -688,6 +688,10 @@
margin: 0 16px 12px;
padding: 8px;
flex-shrink: 0;
+
+ &:hover .agent-chat__input-resize .protyle-block-resize {
+ opacity: 1;
+ }
}
.agent-chat__input-resize {
@@ -697,7 +701,6 @@
.protyle-block-resize[data-resize-axis="height"] {
top: -16px;
bottom: auto;
- opacity: 1;
}
}
diff --git a/app/src/layout/dock/agent/AgentComposerResize.test.ts b/app/src/layout/dock/agent/AgentComposerResize.test.ts
index 66620e0116..36adafcbb6 100644
--- a/app/src/layout/dock/agent/AgentComposerResize.test.ts
+++ b/app/src/layout/dock/agent/AgentComposerResize.test.ts
@@ -29,6 +29,11 @@ const cases = async (source: string, css: string, mobile: boolean) => {
const editor = composer.querySelector<HTMLElement>(".protyle-wysiwyg");
const handle = panel.querySelector<HTMLElement>(".protyle-block-resize");
const tick = () => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
+ const input = async (method: string, params: object) => {
+ await require("electron").ipcRenderer.invoke("composer-input", method, params);
+ await tick();
+ };
+ const moveMouse = (x: number, y: number) => input("Input.dispatchMouseEvent", {type: "mouseMoved", x, y});
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");
@@ -37,6 +42,23 @@ const cases = async (source: string, css: string, mobile: boolean) => {
await tick();
const small = composer.clientHeight;
check.ok(small < 100, `short input stays compact: ${small}`);
+ await moveMouse(900, 10);
+ check.equal(getComputedStyle(handle).opacity, "0", "idle handles stay hidden on devices with a mouse");
+ const inputRect = composer.getBoundingClientRect();
+ await moveMouse(inputRect.left + 10, inputRect.top + 10);
+ check.equal(getComputedStyle(handle).opacity, "1", "hovering the input reveals the handle even for short content");
+ await moveMouse(900, 10);
+ check.equal(getComputedStyle(handle).opacity, "0", "leaving the input hides the handle");
+ await input("Input.dispatchKeyEvent", {type: "keyDown", key: "Tab", code: "Tab", windowsVirtualKeyCode: 9});
+ await input("Input.dispatchKeyEvent", {type: "keyUp", key: "Tab", code: "Tab", windowsVirtualKeyCode: 9});
+ check.equal(document.activeElement, handle, "the handle remains reachable by keyboard");
+ check.equal(getComputedStyle(handle).opacity, "1", "keyboard focus reveals the handle without hover");
+ check.equal(getComputedStyle(handle).outlineStyle, "solid", "keyboard navigation retains its focus indicator");
+ handle.blur();
+ await input("Emulation.setTouchEmulationEnabled", {enabled: true});
+ 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});
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");
@@ -71,13 +93,29 @@ const cases = async (source: string, css: string, mobile: boolean) => {
// 原生指针事件验证捕获、鼠标拖动以及触摸取消。
handle.dispatchEvent(new MouseEvent("dblclick", {bubbles: true}));
await tick();
+ const editable = editor.querySelector<HTMLElement>('[contenteditable="true"]');
+ editable.focus();
const rect = handle.getBoundingClientRect();
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.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 escapeRect = handle.getBoundingClientRect();
+ let escapedEditor = false;
+ editable.addEventListener("keydown", event => escapedEditor ||= event.key === "Escape");
+ await require("electron").ipcRenderer.invoke("composer-drag", {
+ 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(escapedEditor, false, "canceling a drag does not trigger editor Escape actions");
+ check.equal(handle.classList.contains("touch-resize-active"), false);
const touchRect = handle.getBoundingClientRect();
await require("electron").ipcRenderer.invoke("composer-drag", {
x: Math.round(touchRect.left + touchRect.width / 2), y: Math.round(touchRect.top + touchRect.height / 2),
@@ -122,10 +160,13 @@ const cases = async (source: string, css: string, mobile: boolean) => {
destroy();
key("End");
check.equal(composer.style.maxHeight, "", "destroy removes listeners and the temporary geometry");
+ 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 scroll space on desktop and mobile", {
+test("composer grows, resizes and preserves focus, handle visibility and scroll space on desktop and mobile", {
skip: process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY,
timeout: 60000,
}, async () => {
@@ -143,7 +184,8 @@ app.whenReady().then(async () => {
const win = new BrowserWindow({show: false, width: 1000, height: 900,
webPreferences: {nodeIntegration: true, contextIsolation: false, offscreen: true}});
win.webContents.debugger.attach("1.3");
- ipcMain.handle("composer-drag", async (_event, {x, y, dy, touch}) => {
+ ipcMain.handle("composer-input", (_event, method, params) => win.webContents.debugger.sendCommand(method, params));
+ ipcMain.handle("composer-drag", async (_event, {x, y, dy, touch, escape}) => {
const send = async (method, params) => {
await win.webContents.debugger.sendCommand(method, params);
await new Promise(resolve => setTimeout(resolve, 40));
@@ -157,6 +199,10 @@ app.whenReady().then(async () => {
} else {
await send("Input.dispatchMouseEvent", {type: "mousePressed", x, y, button: "left", buttons: 1, clickCount: 1});
await send("Input.dispatchMouseEvent", {type: "mouseMoved", x, y: y + dy, button: "left", buttons: 1});
+ if (escape) {
+ await send("Input.dispatchKeyEvent", {type: "keyDown", key: "Escape", code: "Escape", windowsVirtualKeyCode: 27});
+ await send("Input.dispatchKeyEvent", {type: "keyUp", key: "Escape", code: "Escape", windowsVirtualKeyCode: 27});
+ }
await send("Input.dispatchMouseEvent", {type: "mouseReleased", x, y: y + dy, button: "left", buttons: 0, clickCount: 1});
}
});
diff --git a/app/src/layout/dock/agent/AgentComposerResize.ts b/app/src/layout/dock/agent/AgentComposerResize.ts
index 50b60f8f3a..f1db35ff4b 100644
--- a/app/src/layout/dock/agent/AgentComposerResize.ts
+++ b/app/src/layout/dock/agent/AgentComposerResize.ts
@@ -44,7 +44,6 @@ export const bindAgentComposerResize = (panel: HTMLElement, composer: HTMLElemen
drag = {id: event.pointerId, y: event.clientY, height: composer.clientHeight, previous: preferred};
handle.setPointerCapture(event.pointerId);
handle.classList.add("touch-resize-active");
- handle.focus({preventScroll: true});
};
const move = (event: PointerEvent) => {
if (!drag || drag.id !== event.pointerId) {
@@ -65,10 +64,15 @@ export const bindAgentComposerResize = (panel: HTMLElement, composer: HTMLElemen
}
};
const cancel = () => finish(true);
- const keydown = (event: KeyboardEvent) => {
+ const cancelKeydown = (event: KeyboardEvent) => {
if (event.key === "Escape" && drag) {
cancel();
- } else if (event.key === "ArrowUp" || event.key === "ArrowDown") {
+ event.preventDefault();
+ event.stopPropagation();
+ }
+ };
+ const keydown = (event: KeyboardEvent) => {
+ if (event.key === "ArrowUp" || event.key === "ArrowDown") {
preferred = Math.max(40, Math.min(maximum, value + (event.key === "ArrowUp" ? 24 : -24)));
update();
} else if (event.key === "Home" || event.key === "End") {
@@ -93,6 +97,7 @@ export const bindAgentComposerResize = (panel: HTMLElement, composer: HTMLElemen
handle.addEventListener("keydown", keydown);
handle.addEventListener("dblclick", reset);
windowSelf.addEventListener("blur", cancel);
+ windowSelf.addEventListener("keydown", cancelKeydown, true);
windowSelf.addEventListener("resize", update);
windowSelf.visualViewport?.addEventListener("resize", update);
const observer = new ResizeObserver(update);
@@ -109,6 +114,7 @@ export const bindAgentComposerResize = (panel: HTMLElement, composer: HTMLElemen
handle.removeEventListener("keydown", keydown);
handle.removeEventListener("dblclick", reset);
windowSelf.removeEventListener("blur", cancel);
+ windowSelf.removeEventListener("keydown", cancelKeydown, true);
windowSelf.removeEventListener("resize", update);
windowSelf.visualViewport?.removeEventListener("resize", update);
composer.style.maxHeight = "";