Repository navigation
feat(rune-kit): native code-block soft wrapping and text-wrap icon - #1292
Merged
Merged
Conversation
Add native code-block soft wrapping to `rune-kit::markdown` and the `text-wrap` icon (`icons::TEXT_WRAP`) to `rune-theme-opencode` for `anomalyco/opencode#64545`: - `MarkdownStyle::wrap_code(bool)`, `Markdown::wrap_code(bool)`, and `Markdown::code_wrap(Fn(usize, &str) -> bool)` wrap long lines inside `Renderer::code` via `.by_line().wrap_anywhere().wrap_greedy()` while keeping `#1133` per-line shaping, screen-reader `TextRun` line runs, `#1130` `settled_code_card_digest` memoisation, Find highlights, streaming reveal, `.copy_breaks(2, 2)`, non-mono tab stops, and shell block colours. - Unwrapped blocks (`!wrapped`) remain identical to before. - `Source` computes longest-line tab-expanded stats once at parse time; `CodeFrame::overflows` answers overflow against `text_width - flow.inset` in O(1) on the ASCII monospace fast path (falling back to `rune::text::measure` only near the boundary or for non-ASCII/non-mono). - `CodeFrame::wrapped` reports the block's active wrap state. - `rune-theme-opencode::icons::TEXT_WRAP` adds Desktop's `text-wrap` SVG.
…exact overflows, lock-free font_epoch, line reuse, scoped memo)
…hs on font switch, Acquire/Release font_epoch, bound control chars
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.
Native soft wrapping for Markdown code blocks (
anomalyco/opencode#64545/UP-060) plus theTEXT_WRAPicon inrune-theme-opencode.Summary
Markdown::wrap_code(bool)(defaultfalse) and per-blockMarkdown::code_wrap(Fn(usize, &str) -> bool)wrap long code lines natively insideRenderer::codevia.by_line().wrap_anywhere().wrap_greedy()while keeping#1133line-by-line shaping, screen-readerTextRunline runs,#1130settled-card memoisation, Find highlights, streaming reveal,.copy_breaks(2, 2), tab stops, and shell colours.scroll_wide(true), both wrapped and unwrapped states keep the identicalframe -> col("scroll") -> col(pad) -> bodyelement path (NodeIdpreserved) and keep.wrap_anywhere().wrap_greedy()onbody(no-op whenmax_width = Noneinsidescroll_x()), so toggling wrap never replays word-reveal, never clears active text selection, and reuses already-shaped line layouts through Rune's existingparagraphs.rsrebreak path without reshaping.CodeFrame::overflows()/CodeFrame::overflows_at(scale)compute overflow lazily on demand (zero parse work, zero per-token streaming work, zero work unless called), using exactborder_layout()snapping atscale, lock-free Acquire/Releaserune::text::font_epoch(),TextSystem::ascii_lineadvances +fixed_pitch, and a bounded 256-entry FIFO cache keyed on(PreBlock::digest, len, font, avail, font_epoch).rune-theme-opencode::icons::TEXT_WRAPadds upstream'stext-wrapSVG (packages/ui/src/icons/catalog.ts).unsafeadded;rune-text/src/paragraphs.rsuntouched fromdev.Response to READER-5 (
notes/review-1292.md)scroll_wide(true)remountedbodyat a new path, minting a newNodeId, replaying word-reveal from byte 0 (~55 s on 2k lines), and wiping active selection.render/code.rskeepsframe -> col("scroll") -> col(pad) -> bodyin both states underscroll_wide(true)and sets.wrap_anywhere().wrap_greedy()onbodyunderscroll_wide(visual no-op atmax_width = None, keepingshape_key/style_keystable so Rune's existingrebreakreuses shaped lines without reshaping). Verified inverify-1292: height40 -> 120 -> 40, selection intact,opacity == 1.0.CodeFrame::overflowsfalse negatives/positives (non-ASCII masking,- 1.0border mismatch,fixed_pitch/proportional,avail <= 0.0, nested task checkbox inset).CodeFrame::overflows()/overflows_at(scale)(markdown.rs,render/code.rs) matchingdevice::bordersnapping atscale, using real(advance, widest, fixed_pitch)fromTextSystem::ascii_lineviarune::text::ascii_metrics, independent per-line checks with early exit,avail <= 0.0returningtruefor non-empty code, and nested taskflow.insetfix (render/blocks.rs). Verified all 8 counterexamples inverify-1292.longest_line_statsper parse/token; eagercode_overflowslocking globalFONTSMutex).markdown/parser.rs&markdown/parser/builder.rs(Sourceback to 40 B, zero parse/token scan); madefont_epoch()lock-free; lazy cachedoverflows_atkeyed on precomputed 128-bitPreBlock::digest. Note:scroll_wide(true)wrap-off setswrap_anywhere().wrap_greedy()onbody(timing verified via PROOF-FARM below).wrap_codeinMarkdownStyleenteredcompute_base, invalidating non-code blocks; dual digest inMarkdown::render.markdown/style.rs(wrap_codeonMarkdownonly;compute_baseuntouched);memo.rshasheswrap_code_default()only forHAS_CODE; deduplicatedMarkdown::render. Verifiedblock_builds == 1inverify-1292.9927d4f1)TextSystem.ascii/paragraphs/last_paragraphsafterTx::set_font_familiesor webfollow_full_faces.TextSystem::drop_shaped()(rune-text/src/fonts/families.rs) now clearsself.ascii,self.paragraphs, andself.last_paragraphs;RuntimeCore::follow_font_families()(rune/src/runtime/font_families.rs) clearsn.text_layout = Noneacrossself.tree.nodes.9927d4f1)paragraphs.rstighter/kept_fitsbugs (widening from narrowSome(0.0),alignchange onby_line, trailing whitespace hanging advance) and scope creep.crates/rune-text/src/paragraphs.rscompletely back todev. Measured settled 2,000-line toggle latency WITH vs WITHOUTparagraphs.rs(verify-1292, release, 5% / 50% / 100% long lines):on_1:2.8 / 7.0 / 11.7 mswith vs5.9 / 8.3 / 13.4 mswithout;off:2.0 / 1.8 / 1.4 mswith vs1.8 / 1.5 / 1.7 mswithout;on_2:1.5 / 1.5 / 0.9 mswith vs1.2 / 1.3 / 1.2 mswithout. Fast enough without touching framework-wide paragraph layout; keeping#1292strictly scoped.9927d4f1)GLOBAL_EPOCHRelaxedordering & stores on read-onlywith_state; control chars< 0x20skipped inub.measure.rsnow storesGLOBAL_EPOCHwithOrdering::Releaseonly when epoch actually changes and loads withOrdering::Acquire;render/code.rsbounds all non-printable bytes (< 0x20and>= 0x7f) withnon_ascii_ub.Verification (
9927d4f1)cargo check -p rune-text -p rune -p rune-kit -p rune-theme-opencode --features rune-kit/markdown,rune-kit/mermaid --all-targets: green.cargo check --target wasm32-unknown-unknown -p rune-text -p rune -p rune-kit --features markdown,mermaid -p rune-theme-opencode: green.cargo test -p rune-text --lib -- measure:: fonts::: 18 passed, 0 failed.cargo test -p rune-kit --features markdown,mermaid --lib -- markdown::: 29 passed, 0 failed.verify-1292): all 8overflows_atcounterexamples, stableNodeId/ selection /opacity == 1.0, andblock_builds == 1passed.Shipping-build timings (PROOF-FARM)
rune-desktopmeasurement branchws3/measure-wrap(pinned to Rune0a33155a=dev9553c9a7+#12929927d4f1, vsdevbuilt the same way).