Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(webui): preserve mentions when IME composition is canceled
Xubin Ren78ae5ff94f96
diff --git a/webui/src/lib/composer-mention-text.ts b/webui/src/lib/composer-mention-text.tsindex 7f3b8cdcf..d298e2f64 100644--- a/webui/src/lib/composer-mention-text.ts+++ b/webui/src/lib/composer-mention-text.ts@@ -102,6 +102,10 @@ export function editComposerMentionText(caret: number,selection?: { start: number; end: number },): { value: string; cursor: number } {+ // Canceling IME composition is not an edit, even when its caret is inside a token.+ if (nextDisplay === text.display) {+ return { value: text.raw, cursor: mentionTextOffset(text, caret, "toRaw") };+ }let start = 0;// The caret disambiguates repeated text (e.g. inserting a space before an existing space).while (start < Math.min(text.display.length, nextDisplay.length, caret, selection?.start ?? Infinity)diff --git a/webui/src/tests/composer-mention-text.test.ts b/webui/src/tests/composer-mention-text.test.tsindex 6fe66fe43..34f8e7cb6 100644--- a/webui/src/tests/composer-mention-text.test.ts+++ b/webui/src/tests/composer-mention-text.test.ts@@ -12,6 +12,13 @@ const apps = [const project = (raw: string) => composerMentionText(splitCapabilityMentionSegments(raw, apps));describe("composer mention display text", () => {+ it("preserves the identifier when an IME edit is canceled inside a mention", () => {+ const text = project("@drive next");+ expect(editComposerMentionText(text, text.display, 4, { start: 4, end: 4 }).value)+ .toBe("@drive next");+ expect(editComposerMentionText(text, text.display, 13, { start: 0, end: 13 }).value)+ .toBe("@drive next");+ });it.each([["n @Linear @Google Drive", 0, 0, ["linear", "drive"]],["@Linear n @Google Drive", 8, 8, ["linear", "drive"]],diff --git a/webui/src/tests/thread-composer.test.tsx b/webui/src/tests/thread-composer.test.tsxindex 5115814a2..5b22b5804 100644--- a/webui/src/tests/thread-composer.test.tsx+++ b/webui/src/tests/thread-composer.test.tsx@@ -2384,6 +2384,25 @@ describe("ThreadComposer", () => {});});+ it("does not remove a mention when composition is canceled inside its label", () => {+ const onSend = vi.fn();+ render(<ThreadComposer onSend={onSend} mcpPresets={[+ { ...MCP_PRESETS[0], name: "drive", display_name: "Google Drive" },+ ]} />);+ const input = screen.getByLabelText("Message input") as HTMLTextAreaElement;+ fireEvent.change(input, { target: { value: "@drive next" } });+ input.setSelectionRange(4, 4);+ fireEvent.compositionStart(input);+ fireEvent.change(input, { target: { value: "@\u00a0Gonogle Drive next", selectionStart: 5 } });+ fireEvent.change(input, { target: { value: "@\u00a0Google Drive next", selectionStart: 4 } });+ fireEvent.compositionEnd(input, { data: "" });+ expect(input).toHaveValue("@\u00a0Google Drive next");+ fireEvent.click(screen.getByRole("button", { name: "Send message" }));+ expect(onSend).toHaveBeenCalledWith("@drive next", undefined, {+ mcpPresets: [expect.objectContaining({ name: "drive" })],+ });+ });+it("clears mention editing and undo state when switching sessions during composition", () => {const props = { onSend: vi.fn(), cliApps: CLI_APPS };const { rerender } = render(<ThreadComposer {...props} pendingQueueKey="chat-a" />);