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

Make trailing line breaks count as lines #21

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

QnnOkabayashi
Copy link

Related: #20

This makes the concept of "lines" and line counts align with what we would expect when displaying text in a text editor, e.g. the empty string is 1 line, the string "foo\n" is 2 lines, "foo\nbar" is 2 lines, and so on. The main difference is that trailing newlines now count as another line.

@noib3
Copy link
Collaborator

noib3 commented Aug 6, 2024

LGTM (once Clippy passes), but I wouldn't merge it without the corresponding changes to the Iterator/DoubleEndedIterator impls of RawLines and Lines.

For example, this test should pass:

#[test]
fn lines_iterator_len_mismatch() {
    let r = Rope::from("foo\n");
    assert_eq!(r.lines().len(), 2);

    let mut lines = r.lines();
    assert_eq!(lines.next().unwrap(), "foo");
    assert_eq!(lines.next().unwrap(), "");
    assert_eq!(lines.next(), None);

    let mut lines = r.lines();
    assert_eq!(lines.next_back().unwrap(), "");
    assert_eq!(lines.next_back().unwrap(), "foo");
    assert_eq!(lines.next_back(), None);

}

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

Successfully merging this pull request may close these issues.

2 participants