Fix --wrap-width truncating code blocks + pin Rust toolchain#57
Merged
Conversation
wrap_width and the document's maximum element width were conflated in the parser — a single value used both to wrap prose and to clamp non-wrapping elements like code blocks. Setting --wrap-width 80 on a wider terminal silently truncated code-block lines that exceeded 76 columns, which broke copy/paste of those lines (the rendered content is what gets copied). Split the two: - wrap_width: controls prose word-wrapping (unchanged behavior) - max_width: upper bound for elements that don't word-wrap; equals the available terminal area regardless of --wrap-width Code blocks now use max_width as their clamp, so they extend to the full terminal width even when --wrap-width is narrower. They still truncate when a line exceeds the terminal itself, matching no-flag behavior. Closes #55.
The first fix in this branch moved code-block truncation from wrap_width-4 to terminal_width-4, but a line still narrower than the terminal but wider than wrap_width was the easy case. When a code line is wider than the terminal itself, it still has to truncate visually — and the previous copy path read from the rendered text, so the trailing characters were silently dropped on paste (the original complaint in #55). Selection now looks up the parsed source via Document::code_block_raw_line for any code body line and copies that verbatim. Border lines remain filtered out, and non-code lines keep their existing behavior.
When a code line is wider than the terminal allows, content was clipped to max_width - 4, leaving the frame at max_width + 3. The terminal then clipped the right `│`, the space before it, and one of three padding spaces — leaving two cols of dead whitespace before the visually missing border. Clip content to max_width - 2 instead so visible characters extend to the screen edge. The right border and trailing padding still overflow and get clipped; the missing right `│` remains the indicator that the line was truncated.
CI was using `dtolnay/rust-toolchain@stable`, so every new stable release that added clippy lints could fail CI without anyone changing code. Pin to 1.95.0 in both ci.yml and release.yml, and add rust-toolchain.toml so local rustup picks up the same version automatically. To bump in the future, update all three values together.
Pinning the toolchain surfaces new lints that were never run against the existing code: - input.rs: collapse nested `if` guards into match-arm guards (collapsible_match) - model.rs: replace `sort_by` with `sort_by_key` (unnecessary_sort_by) - types.rs: drop redundant `.into_iter()` in `.zip()` (useless_conversion) - watcher/mod.rs: remove a trailing comma in `format!` args (unnecessary_trailing_comma)
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.
Summary
Closes #55. Three related changes plus a CI hygiene fix.
1. Don't let
--wrap-widthtruncate code blocks (src/document/parser.rs,src/app/model.rs,src/document/mod.rs,src/app/event_loop.rs)wrap_widthwas used both to word-wrap prose AND to clamp the maximum width of non-wrapping elements like code blocks. Setting--wrap-width 80on a wider terminal silently truncated code lines >76 chars, which broke copy/paste of those lines.Split the parser's two width inputs:
wrap_width— controls prose word-wrap (unchanged behavior)max_width— upper bound for elements that don't wrap (code blocks, tables); equals the available terminal area regardless of--wrap-widthNew public API:
Document::parse_with_widths,parse_with_all_options_widths,prepare_document_from_bytes_with_widths. Old API preserved (forwardswidthas both).2. Copy the raw code block source, not the rendered line (
src/app/model.rs,src/document/types.rs)When a line is still wider than the terminal itself, it has to clip visually. The previous selection/copy path read from the rendered text, so the trailing characters were silently dropped on paste — the original complaint in #55. Selection now looks up
Document::code_block_raw_linefor any code body line and copies that verbatim.3. Maximize visible content when truncation is unavoidable (
src/document/parser.rs)Even after fix #1, lines longer than the terminal need to clip. The old clamp at
max_width - 4left the frame atmax_width + 3, so the terminal lopped off the right│, the space before it, and one padding space — visible result had two cols of trailing whitespace before the (missing) border. Clip tomax_width - 2instead so visible content extends to the screen edge. The missing right│remains the truncation indicator.4. Pin the Rust toolchain (
rust-toolchain.toml,.github/workflows/*.yml)Discovered while running pre-push checks for this PR: CI used
dtolnay/rust-toolchain@stable, so any new stable release that added clippy lints could break CI without anyone changing code (this happened to PR #56). Pin to 1.95.0 across bothci.ymlandrelease.ymland addrust-toolchain.tomlso local rustup matches. Bonus: fixed 9 clippy lints from Rust 1.95 in pre-existing code (sort_by_key,collapsible_match,useless_conversion,unnecessary_trailing_comma).Test plan
cargo fmt --checkcargo clippy -- -D warnings(Rust 1.95.0)cargo test— 626 tests pass, 5 new (select_poll_msx3 +parse_with_widthsx3 +wrap_width_does_not_truncate_code_blocks+selected_text_returns_raw_code_line_even_when_rendering_truncates)curl … --importcase from --wrap-width truncates code blocks without an indication #55: code block renders at full width on a wide terminal, paste contains the trailingt│is the missing indicator, paste still returns the original source