Skip to content

Commit

Permalink
Fix issue All-Hands-AI#5186: [Bug]: Fix up inline code styles in chat…
Browse files Browse the repository at this point in the history
… window (All-Hands-AI#5226)

Co-authored-by: Graham Neubig <[email protected]>
Co-authored-by: amanape <[email protected]>
  • Loading branch information
3 people authored Dec 9, 2024
1 parent 3946f81 commit 99fa6c6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
8 changes: 8 additions & 0 deletions frontend/__tests__/components/chat-message.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,12 @@ describe("ChatMessage", () => {
);
expect(screen.getByTestId("custom-component")).toBeInTheDocument();
});

it("should apply correct styles to inline code", () => {
render(<ChatMessage type="assistant" message="Here is some `inline code` text" />);
const codeElement = screen.getByText("inline code");

expect(codeElement.tagName.toLowerCase()).toBe("code");
expect(codeElement.closest("article")).not.toBeNull();
});
});
15 changes: 14 additions & 1 deletion frontend/src/components/features/markdown/code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,20 @@ export function code({
const match = /language-(\w+)/.exec(className || ""); // get the language

if (!match) {
return <code className={className}>{children}</code>;
return (
<code
className={className}
style={{
backgroundColor: "#2a3038",
padding: "0.2em 0.4em",
borderRadius: "4px",
color: "#e6edf3",
border: "1px solid #30363d",
}}
>
{children}
</code>
);
}

return (
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ code {
margin: 0;
font-size: 85%;
white-space: break-spaces;
background-color: var(--bg-neutral-muted);
border-radius: 6px;
background-color: #2a3038;
border-radius: 4px;
color: #e6edf3;
border: 1px solid #30363d;
letter-spacing: -0.2px;
}

.markdown-body pre code {
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/services/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
ObservationMessage,
StatusMessage,
} from "#/types/message";
import EventLogger from "#/utils/event-logger";
import { handleObservationMessage } from "./observations";

const messageActions = {
Expand Down Expand Up @@ -107,6 +106,10 @@ export function handleAssistantMessage(message: Record<string, unknown>) {
} else if (message.status_update) {
handleStatusMessage(message as unknown as StatusMessage);
} else {
EventLogger.error(`Unknown message type ${message}`);
store.dispatch(
addErrorMessage({
message: "Unknown message type received",
}),
);
}
}

0 comments on commit 99fa6c6

Please sign in to comment.