xterm.js icon indicating copy to clipboard operation
xterm.js copied to clipboard

attach images to Markers

Open PerBothner opened this issue 6 months ago • 3 comments

I believe there is agreement that the ExtendedAttrsImage mechanism for attaching images to buffers is problematic. I also believe PR #5853 provides a reasonable solution. I can't say I have a solid understanding of the image addon, but I have some preliminary ideas.

PR #5853 extends a Marker with a payload field. We can use this to link from a Marker to image-related information. Perhas an IImageSpec directly. The loop in ImageStorage.render could be something like:

for (let row = start; row <= end; ++row) {
  const line = buffer.lines.get(row + buffer.ydisp) as IBufferLine;
  if (!line) return;
  if (line.isWrapped && row !== start) { continue; } // already handled
  line.logicalLine.forEachMarker((marker) => {
    if (marker.payload instanceof IImageSpec) {
      drawCalls.push({ imgSpec: marker.payload, ...});
    }
  });
 ...
}

This way we can get rid all the IExtendedAttrsImage complication. There are probably some minor complications with images that span multiple lines. @Jerch - what do you think?

PerBothner avatar May 05 '26 05:05 PerBothner

Sadly we cannot get rid of the ExtendedAttrsImage easily - as described in #5860 this is needed to keep the cell-wise text overwrites working. This is a feature across most to all terminals, so we cannot deviate here easily.

Yes the mechanism behind ExtendedAttrsImage is doomed to fail and I am not opposed to find a better working way. But I don't see yet, how markers can solve that? The issue with markers is, that the PRINT method is completely unaware of them, so text overwrites are not possible at all w'o a bigger rewrite.

jerch avatar May 06 '26 10:05 jerch

When it comes to getting rid of ExtendedAttrsImage`, I think we have 3 choices:

  • Make ExtendedAttrs be properly and officially extensible, either through subclassing or perhaps better a payload hook.
  • Add at least some basic image hooks in the core (like we have for url links).
  • Not use ExtendedAttrs for images at all, perhaps using Markers. Attaching the image info to Markers allows multiple markers to attach to the same cell, but it becomes more complicated to prioritise or combine them. Specifically for images, if you have write images or text such that it overwrites parts of older images it becomes a bit complicated keeping tracking of which images to display where - but using per-cell ExtendedAttrs is relatively simple.

Suggestion: Add a general-purpose payload field to ExtendedAttrs. This can point to an associated IImageSpec. It is easy to check if there is an image at a cell, and I think it's a relatively simple change to the existing logic. A future change could optionally remove the urlId field from ExtendedAttrs to reclaim the space, and perhaps have the payload field point directly to an IOscLinkData object.

PerBothner avatar May 06 '26 17:05 PerBothner

Addressed by #5879, which moved image storage to the new ExtendedAttrs payload field.

xtermjs-bot avatar Oct 29 '26 14:10 xtermjs-bot