Strip carriage returns from all text in text::Buffer
* Moving the logic from Rope to text::Buffer makes it easier to keep the Rope in sync with the fragment tree. * Removing carriage return characters is lossier, but is much simpler than incrementally maintaining the invariant that there are no carriage returns followed by newlines. We may want to do something smarter in the future. Co-authored-by: Keith Simmons <keith@zed.dev>
This commit is contained in:
co-authored by
Keith Simmons
parent
116fa92e84
commit
7e9beaf4bb
@@ -43,6 +43,8 @@ fn test_random_edits(mut rng: StdRng) {
|
||||
.take(reference_string_len)
|
||||
.collect::<String>();
|
||||
let mut buffer = Buffer::new(0, 0, reference_string.clone().into());
|
||||
reference_string = reference_string.replace("\r", "");
|
||||
|
||||
buffer.history.group_interval = Duration::from_millis(rng.gen_range(0..=200));
|
||||
let mut buffer_versions = Vec::new();
|
||||
log::info!(
|
||||
@@ -56,6 +58,8 @@ fn test_random_edits(mut rng: StdRng) {
|
||||
for (old_range, new_text) in edits.iter().rev() {
|
||||
reference_string.replace_range(old_range.clone(), &new_text);
|
||||
}
|
||||
reference_string = reference_string.replace("\r", "");
|
||||
|
||||
assert_eq!(buffer.text(), reference_string);
|
||||
log::info!(
|
||||
"buffer text {:?}, version: {:?}",
|
||||
@@ -148,6 +152,20 @@ fn test_random_edits(mut rng: StdRng) {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_line_endings() {
|
||||
let mut buffer = Buffer::new(0, 0, "one\r\ntwo".into());
|
||||
assert_eq!(buffer.text(), "one\ntwo");
|
||||
assert_eq!(buffer.line_ending(), LineEnding::Windows);
|
||||
buffer.check_invariants();
|
||||
|
||||
buffer.edit([(buffer.len()..buffer.len(), "\r\nthree")]);
|
||||
buffer.edit([(0..0, "zero\r\n")]);
|
||||
assert_eq!(buffer.text(), "zero\none\ntwo\nthree");
|
||||
assert_eq!(buffer.line_ending(), LineEnding::Windows);
|
||||
buffer.check_invariants();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_line_len() {
|
||||
let mut buffer = Buffer::new(0, 0, "".into());
|
||||
|
||||
Reference in New Issue
Block a user