cosmic-text
cosmic-text copied to clipboard
Buffer is lossy / loses source information
When there's an empty line (i.e. "\n"
), the BufferLine
loses Attrs
information from the source. This results in a couple issues:
- When you clear the text in a buffer line, it falls back to the "default"
Attrs
. - Since we don't know the
Attrs
for the empty line it's not possible to recreate the source representation from the buffer representation.
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
).
Solution
Preferred solution is that there is always enforced one span per buffer line, even if it is a zero length span.