Repository navigation
Conversation
…w precedent (GH13735) Model block alignment as start/end BufferText markers plus a SumTree dimension (ordered-list precedent), not a FormattedTextLine::AlignedBlock wrapper. The wrapper collapses into a BufferBlockStyle when lowered into the editor content model, which violates bnavetta's warpdotdev#13345 constraint that only one BufferBlockStyle is active per character (aligned + code block can't compose). Demote the wrapper to a considered-and-rejected alternative. Also: add TUI surface disposition (best-effort within terminal width, left-aligned fallback) as an explicit scope decision; mark warpui_core::Align as a GUI-only paint strategy rather than the content model; fix the feature- gating path to crates/editor/src/content/buffer.rs:850-855; rewrite the Risks blast radius honestly for the marker design (bounded BufferText match sites) versus the rejected wrapper (20 files matching FormattedTextLine, incl. the non-obvious ipynb_parser and warp_tui); cite bnavetta's canonical round-trip ruling on invariant 6.
Specify the concrete parser-to-buffer contract left open in the align spec: region boundaries ride the FormattedTextLine stream as two content-less variants (AlignRegionStart(BlockAlignment)/AlignRegionEnd) that the core.rs edit lowering loop translates into the paired top-level BufferText align markers, mirroring the ordered-list precedent end to end. Boundary lines stay orthogonal to BufferBlockStyle, preserving the composition constraint. Resolve the TUI inconsistency: because boundaries are in the FormattedTextLine stream, the TUI reads them directly from the exhaustive match it already consumes, with no buffer/SumTree involvement. Correct the blast-radius note to own the added FormattedTextLine arms honestly.
Specify the single-line <p align> detection path and its literal fallback for mixed same-line text; gate the feature at the parser crate (mirroring the MarkdownTables bool-threading mechanism through parse_markdown_impl) so GUI and TUI share one gate; define the text-align style micro-grammar precisely.
…blocks (GH13735) Address round-3 review findings on PR warpdotdev#13906. Feature-gating: the existing parse_markdown / parse_markdown_with_gfm_tables entry-point pair encodes a single binary choice and cannot express the state where GFM tables and block alignment are both enabled. Replace the second-boolean evolution with a MarkdownParseOptions { gfm_tables, block_align } struct threaded through one shared parse_markdown_impl, thin public wrappers, and a parse_markdown_with_options entry point; every call site populates both fields from its FeatureFlag checks so all four combinations are well-defined. Attribute contract: add a single Attribute-matching contract subsection that both detector paths (own-line and single-line) cite, covering case-insensitive attribute names, quoted/unquoted values, align= and style= extraction, the align-vs-style conflict winner, ignoring unrelated attributes, and malformed syntax falling back to a literal tag. Fix the stale design-question-7 reference, tie the Security section to the contract, and add tests for quoting variants, name case-insensitivity, unrelated attributes, and the malformed-vs-unrecognized boundary.
…down-align-blocks-impl
Introduce content-less FormattedTextLine::AlignRegionStart(BlockAlignment)
/ AlignRegionEnd boundary variants and a detector for own-line
<div align>/<p align> and single-line <p align> blocks. Both detector
paths funnel through one shared attribute-matching contract (case-
insensitive names, quoting variants, style-wins conflict rule, style
text-align micro-grammar, unrelated attrs ignored, malformed-to-literal,
unrecognized-value-to-unaligned).
Evolve parse_markdown_impl to take a MarkdownParseOptions { gfm_tables,
block_align } struct so tables and block-align compose, keeping the
existing parse_markdown / parse_markdown_with_gfm_tables wrappers and
adding parse_markdown_with_options. The detector only runs when
block_align is set, so the boundary variants are never emitted otherwise.
…dev#13735) Add FeatureFlag::MarkdownBlockAlign (ships dark) and re-export MarkdownParseOptions / parse_markdown_with_options from the crate root. Widen ipynb_to_formatted_text to take MarkdownParseOptions instead of a gfm_tables bool, re-checking both feature flags the same way, so the Jupyter and Markdown surfaces stay in lockstep on both features.
…otdev#13735) Add paired top-level BufferText::Align(AlignMarker) markers modeled on the BufferText::Link precedent: a StyleSummary align counter, an AlignCount SumTree dimension, and an alignment_at_align_count query so a character's enclosing alignment is a SumTree lookup orthogonal to its block style. The core.rs edit loop translates AlignRegionStart/End boundary lines into the paired markers; find.rs ignores them (zero-width) and validation.rs balances them. Serialization brackets the region on the way out: StyledBufferBlocks yields a zero-width AlignBoundary block that re-emits AlignRegionStart/End lines (semantic round-trip), a <div align> wrapper in the markdown string form, and a <div align> element in HTML export. to_markdown now starts at offset 0 so a leading region marker is not clipped. Round-trip test asserts alignment survives markdown -> buffer -> markdown.
Read AlignRegionStart/AlignRegionEnd boundary lines directly from the FormattedTextLine stream, tracking a stack of active alignments so the nearest enclosing region governs each interior line (innermost wins). Center/Right lines are wrapped in a full-width flex row with flex spacers that absorb the leftover pane width; when content fills the pane the spacers collapse and it degrades to left-aligned, the spec's best-effort positioning. Tests cover center, right, and the left-align fallback.
…3735) Thread the MarkdownBlockAlign flag into the plan-view parse entry point (the remaining call site that selects a Markdown parser), and apply rustfmt to the widened ipynb cell_lines signature.
Thread the enclosing region's alignment through the layout pipeline onto the render-model Paragraph, then apply it as a per-line horizontal offset in draw_text. The layout pass tracks the alignment by walking the AlignBoundary blocks in the styled-block stream (innermost region wins), attaches it to each laid-out block via BlockItem::set_alignment, and the paint path shifts each already-shaped line within the block's available width (align_line_offset). Left is a zero offset, so unaligned content is bit-identical to before; content that fills the pane degrades to left-aligned, matching the TUI's best-effort behavior. The offset rides block-level paint positioning: it reads the already- shaped line's width and shifts the paint origin, never crossing the mac text shaper's CFAttributedString encode/decode (that happens upstream during layout), so it is immune to the attribute round-trip class of bug. Since alignment is resolved by stream-walking rather than a positional query, drop the speculative SumTree align dimension and cursor query (AlignCount, alignment_at_align_count, is_aligned, and the StyleSummary align counters) added with the buffer layer; the zero-width markers only need the text-summary and validation bookkeeping that remains. Tested: align_line_offset offset math (left/center/right/no-slack) and a layout-level assertion that set_alignment threads onto the paragraph.
…tdev#13735) Remove FeatureFlag::MarkdownBlockAlign and all gating: the align-region detector now always runs inside the parser, so every entry point emits align regions. A flag is reserved for genuinely complex or risky features like MarkdownTables; block alignment is a bounded parser-plus-paint change with deterministic fallbacks, matching the unflagged raw-HTML-subset siblings (br/kbd/sub/sup) that ship enabled. Revert MarkdownParseOptions back to the plain gfm_tables bool. The struct existed only to compose two independent feature flags; with block_align ungated there is no second flag to compose, so it would be a single-field wrapper around a bool — the plain boolean is the right shape by the code's grain. Drop parse_markdown_with_options; restore the parse_markdown / parse_markdown_with_gfm_tables pair and the gfm_tables: bool threading through buffer.rs, ipynb_parser, and the TUI plan view. Drop the flag-gating tests (flag-off emits-no-region, the override_enabled in the round-trip test); every other test held since the always-on behavior was already the tested path. Update the spec's design question 7 and risks to state the feature ships enabled, with the rationale.
Contributor
Author
|
Pausing alignment until the img tag feature #13721 ships, as that was a core object I wanted to align. |
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.
Closes #13735
Adds horizontal alignment for
<div align>/<p align>blocks in the Markdown viewer — shipping enabled, like the sibling raw-HTML features. This PR contains the approved spec (merged from #13906's branch,specs/GH13735/align/) plus the full implementation, per the spec→impl workflow; the spec PR #13906 is superseded by this one.Recognizes
align="left|center|right"andstyle="text-align:…"on own-line<div>/<p>blocks and single-line<p>captions, through one shared attribute-matching contract (case-insensitive names, quoting variants, style-wins conflict, a small text-align style subset, unrelated-attrs-ignored, malformed→literal, unrecognized-value→unaligned). Alignment is modeled as paired content-model markers (the ordered-list precedent from the #13345 review), orthogonal to block style, so "aligned + code block" composes and copy/export round-trips canonically. A feature flag was considered and intentionally not added: flags guard genuinely complex/risky subsystems (like GFM tables), and this is a bounded parser+paint change with deterministic fallbacks at every boundary.Rendering: the GUI paints aligned regions via per-line horizontal offsets at paint time (the same lever tables use for cell alignment) — the offset reads the already-shaped line width and never touches the platform shaper's attribute round-trip. The TUI reads the same parser boundary stream and renders best-effort within terminal width with a left-aligned fallback.
Tested: parser (22 detector/contract cases), buffer lowering + round-trip, TUI arms, paint-offset math, and layout threading — markdown_parser 157, ipynb_parser 24, warp_editor 485, warp_tui 400; clippy
-D warnings+ fmt clean across all six touched crates.Known limitations, deliberate: selection-highlight/caret rects inside aligned regions are not offset yet (visual-only in the read-only viewer; follow-up), and a partial re-layout starting mid-region degrades to unaligned until the next full rebuild (doesn't arise in the read-only viewer's whole-document rebuilds).
Verification document used for the screenshot