Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buffer is lossy / loses source information #290

Open
tigregalis opened this issue Jul 24, 2024 · 0 comments
Open

Buffer is lossy / loses source information #290

tigregalis opened this issue Jul 24, 2024 · 0 comments

Comments

@tigregalis
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant