feat(web): global word-wrap toggle for code and diff views#985
Open
junmo-kim wants to merge 4 commits into
Open
feat(web): global word-wrap toggle for code and diff views#985junmo-kim wants to merge 4 commits into
junmo-kim wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Findings
- [Minor] Wrap-off is ignored for compact diff views —
DiffViewnow reads the global wrap preference, but the compact branch still hard-codeswhitespace-pre-wrap break-words. Most inline/preview diff call sites omitsize="comfortable", so turning wrap off in a code block does not actually disable wrapping for those diffs. Evidenceweb/src/components/DiffView.tsx:229.
Suggested fix:const shouldWrap = codeWrap const codeColumnTrack = shouldWrap ? 'minmax(0, 1fr)' : 'max-content' // ... codeWrap ? '' : 'overflow-x-auto' // ... cn(codeWrap ? 'w-full' : 'w-max min-w-full', isComfortable ? 'text-sm leading-6' : 'text-xs') // ... shouldWrap ? 'min-w-0 whitespace-pre-wrap break-words' : 'whitespace-pre'
Questions
- None.
Summary
- Review mode: initial
- One wrap-preference consistency issue found in compact diff rendering.
Testing
- Not run (automation):
bunis not installed in this runner (bun: command not found).
HAPI Bot
There was a problem hiding this comment.
Findings
- None.
Questions
- None.
Summary
- Review mode: follow-up after new commits
- No issues found in the latest full diff. The prior compact diff wrap-off consistency issue appears addressed. Residual risk: browser layout behavior was reviewed statically only in this runner.
Testing
- Not run (automation):
bunis not installed in this runner (bun: command not found).
HAPI Bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #905.
Problem
The web UI renders code blocks, unified diffs, and long tool output/input with horizontal scrolling only (
overflow-x-auto). On narrow screens — Android PWA, phones — long lines run off the right edge and you have to scroll sideways to read them, which is awkward mid-conversation.Solution
Add a word-wrap toggle next to the copy button in the code block header. The preference is stored globally in
localStorage(hapi-code-wrap, default off), so one toggle applies to every code block, diff, and tool input/output at once, and it survives reloads.To keep line numbers aligned when a line wraps, code blocks now render one grid row per logical line — a line-number cell and a code cell as siblings in the same row. When the code cell wraps, the row grows taller and the number stays pinned to the first visual line, matching the GitHub / VS Code gutter behavior. This replaces the previous two independent
<pre>columns, whose separate text flows drifted out of alignment when wrapped. Rendering falls back to plain-text line splitting (with the same normalization) while highlighting is pending or the language is unsupported, so line numbers always match.This PR also adds a lightly shaded gutter background behind the line numbers, consistent in light and dark themes, so the line-number column reads as a distinct gutter.
Default is off, so existing horizontal-scroll rendering is unchanged unless the user turns wrap on.
Usage
Click the wrap icon in any code block header. The setting is remembered across the session and all code/diff/tool views.
Tests
useCodeWrappersistence + same-tab sync; per-line rendering (line count, wrap on/off, plain-text fallback); wrap-toggle suppression when a code block is nested inside an interactive ancestor (avoids nested<button>);<pre>preformatted semantics.Reviewing
Commits are split for review:
refactor(web): add per-line shiki line-splitting helperfeat(web): add global word-wrap toggle for code, markdown, and diff viewsfeat(web): add a shaded gutter background behind line numbersIf the gutter background (commit 3) is out of scope for you, it drops cleanly on its own without touching the wrap feature.