Skip to content

Support overlap option to reduce virtual padding when image covers existing buffer lines #349

@charlesg3

Description

@charlesg3

Problem

When rendering inline images that overlap existing buffer content (e.g. a diagram rendered on top of its source code block), image.nvim always reserves the full image height as virtual padding. This pushes content below the image further down than necessary, since some of that space is already occupied by buffer lines.

There's also no way to use negative render_offset_top values to shift an image upward — the current code guards with > 0 checks.

Proposed solution

  1. New overlap option in from_file(): specifies how many buffer lines the image covers. The extmark virtual padding is reduced by this amount: math.max(0, height + render_offset_top - overlap + 1). When the image is taller than the overlapped lines, only the excess gets virtual padding. When it's shorter, no virtual padding is added.

  2. Support negative render_offset_top: simplify the > 0 guards in renderer.lua to always apply the offset (defaulting to 0), enabling upward shifts.

Use case

diagram.nvim can count the lines in a code fence block and pass that as overlap, so rendered diagrams overlay their source code without pushing subsequent content down.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions