cosmic-text icon indicating copy to clipboard operation
cosmic-text copied to clipboard

Buffer is lossy / loses source information

Open tigregalis opened this issue 7 months ago • 0 comments

When there's an empty line (i.e. "\n"), the BufferLine loses Attrs information from the source. This results in a couple issues:

  1. When you clear the text in a buffer line, it falls back to the "default" Attrs.
  2. Since we don't know the Attrs for the empty line it's not possible to recreate the source representation from the buffer representation.

image

Reproduction

Example reproduction: Replace the set_buffer_text function in the rich-text example with the below.

fn set_buffer_text<'a>(buffer: &mut BorrowedWithFontSystem<'a, Buffer>) {
    let attrs = Attrs::new();

    let spans: &[(&str, Attrs)] = &[
        ("Line 1\n", attrs.color(Color::rgb(0xFF, 0xFF, 0x00))),
        ("Line 2\n", attrs.color(Color::rgb(0xFF, 0x7F, 0x00))),
        ("x\n", attrs.color(Color::rgb(0xFF, 0x00, 0x00))),
        ("Line 4", attrs.color(Color::rgb(0x00, 0xFF, 0x00))),
    ];

    buffer.set_rich_text(spans.iter().copied(), attrs, Shaping::Advanced);
}

Delete x, type a, it's a different Attrs (the buffer's default Attrs). image

image

image

Solution

Preferred solution is that there is always enforced one span per buffer line, even if it is a zero length span.

tigregalis avatar Jul 24 '24 14:07 tigregalis