Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

fix(web): keep Agent mentions drawn while an input method composes

jeffreye5af8b1e8074
diff --git a/apps/web/src/app/globals.css b/apps/web/src/app/globals.css
index 49acb700..88d488e8 100644
--- a/apps/web/src/app/globals.css
+++ b/apps/web/src/app/globals.css
@@ -2757,14 +2757,9 @@ a[href][aria-disabled="true"],
background: color-mix(in srgb, var(--app-info) 24%, transparent);
}
-.message-composer-input[data-composing="true"] {
- color: var(--app-ink);
- -webkit-text-fill-color: var(--app-ink);
-}
-
-.message-composer-input[data-composing="true"]
- + .message-composer-highlight-layer {
- visibility: hidden;
+.message-composer-composition {
+ text-decoration: underline;
+ text-underline-offset: 2px;
}
.message-composer-highlight-layer {
diff --git a/apps/web/src/features/rooms/chat/message-composer.test.tsx b/apps/web/src/features/rooms/chat/message-composer.test.tsx
index 804ba850..451545a6 100644
--- a/apps/web/src/features/rooms/chat/message-composer.test.tsx
+++ b/apps/web/src/features/rooms/chat/message-composer.test.tsx
@@ -191,11 +191,9 @@ describe("MessageComposer", () => {
fireEvent.change(editor, { target: { selectionStart: 1, value: "@" } });
expect(screen.getByRole("option", { name: /Alice/ })).toBeVisible();
fireEvent.compositionStart(editor);
- expect(editor).toHaveAttribute("data-composing", "true");
fireEvent.keyDown(editor, { key: "Enter", isComposing: true });
fireEvent.compositionEnd(editor);
- expect(editor).not.toHaveAttribute("data-composing");
expect(editor).toHaveValue("@");
expect(screen.getByRole("option", { name: /Alice/ })).toBeVisible();
expect(onSend).not.toHaveBeenCalled();
@@ -379,6 +377,40 @@ describe("MessageComposer", () => {
expect(editor).toHaveStyle({ overflowY: "hidden" });
});
+ it("keeps an Agent mention drawn while an input method composes after it", () => {
+ const codex = {
+ display_name: "Codex",
+ id: "actor-codex",
+ kind: "agent" as const,
+ tenant_id: "tenant-1",
+ };
+ const { container } = render(
+ <MessageComposer mentionOptions={[codex]} onSend={vi.fn()} />,
+ );
+ const editor = screen.getByLabelText<HTMLTextAreaElement>("Message Room");
+
+ fireEvent.change(editor, { target: { value: "@Cod" } });
+ fireEvent.click(screen.getByRole("option", { name: /Codex/ }));
+ const committed = editor.value;
+ editor.setSelectionRange(committed.length, committed.length);
+ fireEvent.compositionStart(editor);
+ fireEvent.compositionUpdate(editor, { data: "a" });
+ fireEvent.change(editor, {
+ target: {
+ selectionStart: committed.length + 1,
+ value: `${committed}a`,
+ },
+ });
+
+ expect(container.querySelector(".composer-agent-mention")).not.toBeNull();
+ expect(
+ container.querySelector(".message-composer-composition"),
+ ).toHaveTextContent("a");
+ fireEvent.compositionEnd(editor);
+ expect(container.querySelector(".message-composer-composition")).toBeNull();
+ expect(container.querySelector(".composer-agent-mention")).not.toBeNull();
+ });
+
it("submits selected Actor identities and Files as one composition", () => {
const onSend = vi.fn();
const codex = {
diff --git a/apps/web/src/features/rooms/chat/message-composer.tsx b/apps/web/src/features/rooms/chat/message-composer.tsx
index 45212501..5c58c83c 100644
--- a/apps/web/src/features/rooms/chat/message-composer.tsx
+++ b/apps/web/src/features/rooms/chat/message-composer.tsx
@@ -634,6 +634,11 @@ function ComposerEditor({
controller: MessageComposerController;
peek: ReturnType<typeof useComposerPeek>;
}) {
+ // The overlay keeps drawing mentions while an input method composes; it
+ // underlines the uncommitted text itself, as the hidden textarea would.
+ const [composition, setComposition] = useState<ComposerComposition | null>(
+ null,
+ );
return (
<div className="message-composer-editor relative">
<textarea
@@ -662,18 +667,25 @@ function ComposerEditor({
event.target.selectionStart ?? event.target.value.length,
);
}}
- onCompositionEnd={(event) => {
+ onCompositionEnd={() => {
isComposing.current = false;
- delete event.currentTarget.dataset.composing;
+ setComposition(null);
}}
onCompositionStart={(event) => {
isComposing.current = true;
- event.currentTarget.dataset.composing = "true";
+ const start = event.currentTarget.selectionStart;
+ setComposition({ start, end: start });
}}
// Input-method candidates count as typing before they commit.
- onCompositionUpdate={(event) =>
- peek.typed(event.currentTarget.value.length)
- }
+ onCompositionUpdate={(event) => {
+ peek.typed(event.currentTarget.value.length);
+ const data = event.data;
+ setComposition((current) =>
+ current
+ ? { start: current.start, end: current.start + data.length }
+ : current,
+ );
+ }}
onKeyDown={handleKeyDown}
onPaste={(event) => {
peek.pasted();
@@ -695,6 +707,7 @@ function ComposerEditor({
/>
<ComposerHighlight
body={visibleBody}
+ composition={composition}
documentOptions={documentOptions}
documentReferences={documentReferences}
highlightContentRef={highlightContentRef}
@@ -879,8 +892,14 @@ type ComposerReferenceMatch =
token: string;
};
+interface ComposerComposition {
+ start: number;
+ end: number;
+}
+
function ComposerHighlight({
body,
+ composition,
documentOptions,
documentReferences,
highlightContentRef,
@@ -891,6 +910,7 @@ function ComposerHighlight({
skillReferences,
}: {
body: string;
+ composition?: ComposerComposition | null;
documentOptions: MessageDocumentOption[];
documentReferences: RoomComposerDocumentReference[];
highlightContentRef: RefObject<HTMLDivElement | null>;
@@ -910,15 +930,35 @@ function ComposerHighlight({
);
const content = [];
let cursor = 0;
-
- for (const reference of references) {
- if (reference.start > cursor) {
+ const pushText = (start: number, end: number) => {
+ const marked =
+ composition && composition.end > composition.start
+ ? {
+ start: Math.max(start, composition.start),
+ end: Math.min(end, composition.end),
+ }
+ : null;
+ if (!marked || marked.start >= marked.end) {
content.push(
- <span aria-hidden="true" key={`text-${cursor}`}>
- {body.slice(cursor, reference.start)}
+ <span aria-hidden="true" key={`text-${start}`}>
+ {body.slice(start, end)}
</span>,
);
+ return;
}
+ content.push(
+ <span aria-hidden="true" key={`text-${start}`}>
+ {body.slice(start, marked.start)}
+ <span className="message-composer-composition">
+ {body.slice(marked.start, marked.end)}
+ </span>
+ {body.slice(marked.end, end)}
+ </span>,
+ );
+ };
+
+ for (const reference of references) {
+ if (reference.start > cursor) pushText(cursor, reference.start);
if (reference.kind === "skill") {
content.push(
<SkillReferenceToken
@@ -995,13 +1035,7 @@ function ComposerHighlight({
cursor = reference.end;
}
- if (cursor < body.length) {
- content.push(
- <span aria-hidden="true" key={`text-${cursor}`}>
- {body.slice(cursor)}
- </span>,
- );
- }
+ if (cursor < body.length) pushText(cursor, body.length);
return (
<div