diff --git a/CHANGELOG.md b/CHANGELOG.md index bc7763141..16bb32f1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ All notable changes to **omp-web** (`@kahme247/ompweb`) are documented in this f ### Fixes & Improvements - **Messages sent during a run no longer all turn into “Not sent: it may have been sent.”** After several prompts reached OMP in quick succession (for example automatic PR-update prompts), every later message to that session could fail this way while OMP still showed it, until an idle send restarted the session's OMP process. Now, at the end of each run and before an idle send, the web server asks OMP whether everything it accepted has settled, and only then trusts new messages' echoes again, without restarting OMP. Sessions shared through a host daemon recover too. Messages already marked uncertain stay that way and are never resent. +- **The file viewer highlights more file types, and you can pick the language.** `.diff` and `.patch` files now show added and removed lines in color instead of plain text, and so do `.proto`, `.ini`/`.cfg`/`.conf`, `.mk`, `.kts` and `.cc`/`.cxx`/`.hh` files. `.tsx`/`.jsx` files now color JSX tags, and `.scss` files use the SCSS grammar. For any other file, the language menu in the source view's toolbar applies a grammar by hand (or plain text); it resets to **Auto** when you open another file. - **Delivered messages leave every shared-server chat's pending list.** When another web-server process delivers a message from the shared outbox, open chats now receive its updated state and delivery confirmation without switching sessions or reloading. Startup retries resync existing chats, observer failures cannot interrupt delivery or other observers, and pending, failed and delivered messages retain their historical session identities through repeated native moves. Per-session revisions prevent unrelated database writes from resending unchanged chat payloads. - **A pending message is replaced, never dropped.** With an OMP that reports `supportsClientMessageIds`, each message carries its outbox ID to OMP, and the pending row stays until that exact message, queue entry or explicit withdrawal appears in the chat, even when another server delivers it or its echo arrives late. If OMP no longer has any trace of it (its process ended, or `/new` ran while it was queued), the row turns into **Not sent: it may have been sent** and can be dismissed. An older OMP is sent messages as before and their rows clear on delivery. - **Anthropic stays visible when usage limits are unavailable.** The Provider Usage panel keeps accounts that omp reports without usage data and marks them as unavailable rather than unlimited. diff --git a/app/globals.css b/app/globals.css index 84ad66b57..d6cc805b4 100644 --- a/app/globals.css +++ b/app/globals.css @@ -1593,6 +1593,10 @@ html[data-touch-targets="accessible"] :is(.image-lightbox-stepper button, .image min-height: 35px; } +.file-viewer-shell { + container: file-viewer / inline-size; +} + .file-viewer-path { flex: 1 1 auto; min-width: 48px; @@ -1661,6 +1665,45 @@ html[data-touch-targets="accessible"] :is(.image-lightbox-stepper button, .image filter: brightness(1.08); } +.file-viewer-language-select { + height: 24px; + max-width: 140px; + padding: 0 6px; + border: 1px solid var(--border); + border-radius: var(--radius-control); + background: var(--bg); + color: var(--text-muted); + font: inherit; + font-size: 11px; + cursor: pointer; +} + +.file-viewer-language-select:hover { + color: var(--text); +} + +/* A narrow panel moves the controls to their own row, wrapping them again + rather than clipping the view modes or Download. */ +@container file-viewer (max-width: 440px) { + .file-viewer-toolbar { + flex-wrap: wrap; + row-gap: 5px; + } + + .file-viewer-meta { + display: none; + } + + .file-viewer-controls { + flex-shrink: 1; + flex-wrap: wrap; + justify-content: flex-end; + row-gap: 5px; + min-width: 0; + margin-left: auto; + } +} + .file-viewer-icon-button { display: inline-flex; align-items: center; @@ -1695,7 +1738,8 @@ html[data-touch-targets="accessible"] :is(.image-lightbox-stepper button, .image } .file-viewer-mode-button:focus-visible, -.file-viewer-icon-button:focus-visible { +.file-viewer-icon-button:focus-visible, +.file-viewer-language-select:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; } diff --git a/components/FileViewer.language.test.mjs b/components/FileViewer.language.test.mjs new file mode 100644 index 000000000..109545fab --- /dev/null +++ b/components/FileViewer.language.test.mjs @@ -0,0 +1,57 @@ +import assert from "node:assert/strict"; +import "../tests/setup-dom.mjs"; +import test, { afterEach } from "node:test"; +import React from "react"; +const { cleanup, fireEvent, render, waitFor } = await import("@testing-library/react/pure.js"); + +const { FileViewer } = await import("./FileViewer.tsx"); + +const originalFetch = globalThis.fetch; +const originalWorker = globalThis.Worker; +afterEach(async () => { + await React.act(async () => { + await new Promise((resolve) => setTimeout(resolve, 50)); + cleanup(); + }); + globalThis.fetch = originalFetch; + globalThis.Worker = originalWorker; + delete window.matchMedia; +}); + +const PATCH = "--- a/x\n+++ b/x\n-old\n+new\n"; + +function setup() { + globalThis.fetch = async (url) => { + const body = String(url).startsWith("/api/git/") ? { supported: false } : { content: PATCH, language: "text", size: PATCH.length }; + return { ok: true, json: async () => body }; + }; + globalThis.Worker = class { onmessage = null; onerror = null; postMessage() {} }; + window.matchMedia = () => ({ matches: false, addEventListener() {}, removeEventListener() {} }); +} + +const props = (filePath) => ({ filePath, hostId: "local", cwd: "/ws", sourceSessionId: "s1" }); + +test("the language picker highlights a file whose extension maps to no grammar, and resets for the next file", async () => { + setup(); + const view = render(React.createElement(FileViewer, props("/ws/change.txt"))); + const picker = await waitFor(() => { + const select = view.container.querySelector("select.file-viewer-language-select"); + assert.ok(select); + return select; + }); + assert.equal(picker.value, ""); + assert.equal(view.container.querySelector(".file-source-view .token"), null); + + fireEvent.change(picker, { target: { value: "diff" } }); + await waitFor(() => assert.ok(view.container.querySelector(".file-source-view .token"))); + + // Leaving the tab and coming back to the same file keeps the pick. + view.rerender(React.createElement(FileViewer, { ...props("/ws/change.txt"), active: false })); + view.rerender(React.createElement(FileViewer, props("/ws/change.txt"))); + await waitFor(() => assert.ok(view.container.querySelector(".file-source-view .token"))); + assert.equal(view.container.querySelector("select.file-viewer-language-select").value, "diff"); + + view.rerender(React.createElement(FileViewer, props("/ws/other.txt"))); + await waitFor(() => assert.equal(view.container.querySelector(".file-source-view .token"), null)); + assert.equal(view.container.querySelector("select.file-viewer-language-select").value, ""); +}); diff --git a/components/FileViewer.tsx b/components/FileViewer.tsx index ba662f9d4..608cfeae8 100644 --- a/components/FileViewer.tsx +++ b/components/FileViewer.tsx @@ -5,6 +5,7 @@ import type { SyntaxHighlighterProps } from "react-syntax-highlighter"; import { createSyntaxElement as renderSyntaxNode, ensureLanguageRegistered, + HIGHLIGHT_LANGUAGES, isLanguageRegistered, SyntaxHighlighter, vs, @@ -823,6 +824,8 @@ function TextFileViewer({ filePath, hostId, cwd, sourceSessionId, onOpenFile, on }, [data]); const [displayMode, setDisplayMode] = useState("source"); const [wrapLines, setWrapLines] = useState(false); + // Picked by the user when the extension maps to the wrong grammar or none; null = detected. + const [languageOverride, setLanguageOverride] = useState(null); const [watching, setWatching] = useState(false); const gitDiffRequestRef = useRef(0); const contentRequestRef = useRef(0); @@ -876,6 +879,11 @@ function TextFileViewer({ filePath, hostId, cwd, sourceSessionId, onOpenFile, on } }, [cwd, hostId]); + // Reset per file, not per activation: switching tabs back keeps the user's pick. + useEffect(() => { + setLanguageOverride(null); + }, [filePath]); + // Initial load + SSE watch setup useEffect(() => { if (!active) { @@ -1121,6 +1129,18 @@ function TextFileViewer({ filePath, hostId, cwd, sourceSessionId, onOpenFile, on
{displayMode === "source" && ( <> + + +