Repository navigation
feat(editor): render markdown images inline - #430
Merged
Merged
Conversation
Show standalone Markdown images in normal mode, and reveal the raw source on the cursor line. Detect Kitty, iTerm2, and Sixel, then fall back to half-blocks or a text placeholder.
Terminal graphics sit above the cell grid, so a which-key popup drawn in cells was hidden by the image. Kitty placements now use z=-1, and any image a popup, menu, or hover covers is removed until that overlay closes, then placed again.
Linux can return ETXTBSY for a moment after the staged update's write handle closes. Spawn retries that case. The Windows jq smoke test also allows process creation to finish before treating the filter as hung.
Contributor
Author
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
fcoury
marked this pull request as ready for review
November 3, 2026 00:28
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 27d29000f6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
A forced redraw cleared Kitty placement ids before the delete was sent, so PageDown and a popup left the previous image on screen. Emit those deletes first, move a placement when only its row changes, and crop an image that is only partly in the viewport. Herdr, tmux, and zellij use half-blocks in auto mode because they do not reliably relay deletes. Popup cells use an explicit RGB background. Remote images stop as soon as they pass the size cap, and the cell fingerprint is taken after every visible image row is painted.
Herdr, tmux, and Zellij keep Kitty graphics when their capability query succeeds. A leaked Ghostty variable no longer forces half-blocks, and GNU screen still falls back when the query fails. Kitty and Sixel rasters are resampled to the cell rectangle in pixels. The size comes from CSI 16 t or TIOCGWINSZ, with a 10x20 default when a multiplexer reports zero. iTerm2 sends the original pixels. The text fallback resamples with Lanczos and draws quadrant blocks.
Graphics mode was still painting quadrant cells in the image rectangle. Those cells have their own background, so a z=-1 placement showed through only the gaps and looked patchy. A popup deleted the placement and left the blocks, which made the whole picture go low-resolution. Kitty placements now stay up under an overlay. The rectangle is blank spaces, and the popup covers the overlap with its opaque background. Sixel and iTerm2 still drop while a popup intersects them.
Herdr draws Kitty images above cell backgrounds, so an opaque popup cannot cover a z=-1 placement. When a popup intersects an image, delete that placement and add placements for the remaining cells, using source rectangles. The pixels are transmitted once and reused when the popup closes. Sixel and iTerm2 still drop for the whole image while a popup intersects them.
A partial viewport scaled the whole raster into the remaining rows, and landing on the image line collapsed that block so everything below jumped. Crop Kitty, Sixel, and iTerm2 to the visible rows at a constant pixels-per-row, and show the raw declaration in the block's first row.
j on a revealed image line treated the picture as soft wraps, so column 0 landed inside the block and snapped back. Walk only the declaration text, then the next buffer line. On macOS, /var and /private/var name one workspace when canonicalize fails, so a saved agent conversation is not dropped.
canonicalize rewrites /var and /tmp through /private. When that call failed, the raw path and the canonical path were stored as two workspaces, so the saved conversation was not the record the next launch loaded. One identity is used for the lock, the filename, and the record, and the private prefix is applied even if canonicalize fails. No retry.
A macOS temp path is long enough to wrap  onto a second row, so the line under the picture moved. The test now uses a short relative path, and each wrapped text row takes an image row so the block height stays the same when the source is wider than the window.
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.
Standalone Markdown image lines are invisible as pictures today: concealment only hides the
markup and leaves the alt text. This prototype draws the image in the buffer while the cursor is somewhere else, and keeps that block the same height when the source is showing.Scrolling a tall image used to scale the whole raster into whatever rows were still on screen, so the picture squashed, top bar included. Landing on the
line removed the image and pulled every line below it up by the height of the block.Pressing
jon that declaration did nothing from column 0: the picture rows were treated as soft wraps of the same line, so the motion landed inside the image and snapped back.jandknow walk only the declaration's own text, including its real wraps, and then step to the neighboring buffer line. Counts, half-page motion,gg/G, and the mouse wheel do not stop on picture rows.What changed
In a Markdown buffer, a line whose only content is
becomes an image block in Normal mode. The block reserves vertical rows from the picture's aspect ratio and the terminal's cell aspect, capped bymarkdown_image_max_height(default 16). Moving the cursor onto that line shows the original Markdown in the block's first row. The remaining image rows stay underneath it, sojandkstep onto the declaration and then past the block, and the lines below do not move.When the top or the bottom of an image leaves the viewport, Red crops to the visible rows. Kitty transmits the scaled raster once and places only the visible slice: source
yandhare the hidden and visible rows times that raster's pixels-per-row, andris the visible row count. Sixel and iTerm2 encode that same cropped slice. The pixels-per-row stay constant as the scroll offset changes.markdown_images = "auto"asks the terminal before it trusts environment variables. The probe is the Kitty graphics query (\x1b_Gi=31,...a=q...) plus primary DA, with a short timeout. A successful answer selects that protocol even inside a multiplexer.Herdr (
HERDR_ENV=1orTERM_PROGRAM=herdr) parses the Kitty graphics protocol in the pane and draws it on a Kitty-capable outer terminal such as Ghostty. It does not use tmux passthrough. Zellij 0.45+ does the same. Tmux relays the protocol only when passthrough is enabled, so those queries and later placements, deletes, moves, and crops are wrapped in\x1bPtmux;. GNU screen does not relay graphics; a failed query there stays on half-blocks. A leakedGHOSTTY_RESOURCES_DIRorKITTY_WINDOW_IDdoes not select Kitty inside any of these.Kitty and Sixel bitmaps are the cell rectangle in real pixels (
columns * cell width,rows * cell height), resampled with Lanczos and never enlarged past the source. Cell size comes fromCSI 16 t(CSI 6 ; height ; width t), thenTIOCGWINSZpixel size divided by the character grid. When a multiplexer reports zero, the size is 10×20. Kittyc/rfit that raster into the cells. iTerm2 receives pixels withwidth/heightin cells andpreserveAspectRatio=1. Deletes name both the image id and the placement id (a=d,d=i,i=ID,p=ID), which keeps the transmitted pixels.The text fallback resamples with Lanczos and draws quadrant block elements (the same Unicode block as
▀, including▘▝▖▗). Sextants are not used; that Legacy Computing block is missing from many fonts. Half-blocks remain the glyph when the 2×2 sample is a horizontal split. Those glyphs are not drawn under a Kitty placement. The cells there are blank spaces, so they do not punch holes in the picture.Herdr composites Kitty images above cell backgrounds. An opaque popup cannot cover a
z=-1placement. When a popup intersects an image, Red deletes that placement and adds up to four placements for the remaining cells, using Kitty source rectangles (x,y,w,h) and matchingc/rat the cell offset of each piece. The image is transmitted once witha=tand reused. Closing the popup deletes the fragments and restores one full placement. Sixel and iTerm2 drop for the whole image while a popup intersects them, so none of their pixels sit under the popup.Remote images are read in chunks and stop at 8MB. A forced redraw deletes tracked Kitty placements before it forgets their ids.
On macOS, a workspace path is named the same way when
canonicalizefails as when it succeeds, so/varand/private/varare one directory. A saved agent conversation is no longer dropped when the first lookup fails.Terminal support
i=31;OK, including through Herdr, Zellij, and tmux passthrough. Direct terminals may also match Kitty, Ghostty, WezTerm, or Konsole when no multiplexer is present.c/rand source rectangles. A popup splits the image. A scroll crops it at a constant pixels-per-row.TERM_PROGRAM=iTerm.app/LC_TERMINAL=iTerm2/ VS Code, and only outside a multiplexer unless a query selected something else.width/height,preserveAspectRatio=1.4, or foot/mlterm/Windows Terminal outside a multiplexer. Inside a multiplexer, only when DA1 says so.autowhen the query fails and the terminal is truecolor, ormarkdown_images = "halfblocks".▀for a horizontal split.off, or neither graphics nor truecolor.[image: alt (path)]HERDR_ENV=1orTERM_PROGRAM=herdr. Native Kitty parser, no passthrough wrap.TMUXset. Wrapped query.ZELLIJorZELLIJ_SESSION_NAME. Native Kitty parser.STYorTERM=screen.Demo
Recorded with VHS in a truecolor terminal using JetBrainsMono Nerd Font. VHS does not composite Kitty graphics, so the Kitty stills show the cell layer only.
The declaration replaces the first image row.
after the picturestays on the same screen row:Cells under a Kitty image. The before frame is the quadrant fallback painted in the rectangle. The after frame leaves that rectangle blank:
Text fallback, nearest-neighbor half-blocks compared with the resampled quadrant rendering:
Half-blocks, then the source on the image line, then Insert mode, then the image again:
Keymap popup drawn over the image, then the image restored after Escape:
Placeholder with
markdown_images = "off":How to Test
Scroll until the top or the bottom of a tall image leaves the window. The visible portion should keep its shape. Move the cursor onto the
![...]line. The source appears in the first row of the block, the picture stays in the rows below, and the following line does not jump. From column 0 or the end of a single-row declaration,jgoes to the next buffer line and keeps the desired column. On a wrapped declaration,jsteps through the text rows first.kfrom the following line comes back. Picture rows are skipped.Inside Herdr on Ghostty, leave
markdown_imagesatauto. The picture should be sharp across the whole rectangle, with no quadrant patches. Pressg. The popup must contain no image pixels, and the rest of the image must stay sharp.Escrestores one full placement with no ghost.PageDownremoves it when the line leaves the screen.cargo test --lib markdown_images cargo clippy --all-targets --all-features -- -D warningsThe library tests cover a constant pixels-per-row across scroll offsets, a top crop that is placed instead of rescaled, Sixel and iTerm2 bitmaps cropped to the visible rows, a declaration line that keeps the block height,
jfrom column 0 and from the end of that line,kback onto it, blank cells under a Kitty image, and placements that do not intersect a popup rectangle.