Indent guides (#11503)
Builds on top of existing work from #2249, but here's a showcase: https://github.com/zed-industries/zed/assets/53836821/4b346965-6654-496c-b379-75425d9b493f TODO: - [x] handle line wrapping - [x] implement handling in multibuffer (crashes currently) - [x] add configuration option - [x] new theme properties? What colors to use? - [x] Possibly support indents with different colors or background colors - [x] investigate edge cases (e.g. indent guides and folds continue on empty lines even if the next indent is different) - [x] add more tests (also test `find_active_indent_index`) - [x] docs (will do in a follow up PR) - [x] benchmark performance impact Release Notes: - Added indent guides ([#5373](https://github.com/zed-industries/zed/issues/5373)) --------- Co-authored-by: Nate Butler <1714999+iamnbutler@users.noreply.github.com> Co-authored-by: Remco <djsmits12@gmail.com>
This commit is contained in:
parent
3eb0418bda
commit
feea607bac
27 changed files with 1705 additions and 65 deletions
|
@ -619,10 +619,12 @@ impl<'a> Chunks<'a> {
|
|||
}
|
||||
|
||||
pub fn lines(self) -> Lines<'a> {
|
||||
let reversed = self.reversed;
|
||||
Lines {
|
||||
chunks: self,
|
||||
current_line: String::new(),
|
||||
done: false,
|
||||
reversed,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -726,6 +728,7 @@ pub struct Lines<'a> {
|
|||
chunks: Chunks<'a>,
|
||||
current_line: String,
|
||||
done: bool,
|
||||
reversed: bool,
|
||||
}
|
||||
|
||||
impl<'a> Lines<'a> {
|
||||
|
@ -737,13 +740,26 @@ impl<'a> Lines<'a> {
|
|||
self.current_line.clear();
|
||||
|
||||
while let Some(chunk) = self.chunks.peek() {
|
||||
let mut lines = chunk.split('\n').peekable();
|
||||
while let Some(line) = lines.next() {
|
||||
self.current_line.push_str(line);
|
||||
if lines.peek().is_some() {
|
||||
self.chunks
|
||||
.seek(self.chunks.offset() + line.len() + "\n".len());
|
||||
return Some(&self.current_line);
|
||||
let lines = chunk.split('\n');
|
||||
if self.reversed {
|
||||
let mut lines = lines.rev().peekable();
|
||||
while let Some(line) = lines.next() {
|
||||
self.current_line.insert_str(0, line);
|
||||
if lines.peek().is_some() {
|
||||
self.chunks
|
||||
.seek(self.chunks.offset() - line.len() - "\n".len());
|
||||
return Some(&self.current_line);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let mut lines = lines.peekable();
|
||||
while let Some(line) = lines.next() {
|
||||
self.current_line.push_str(line);
|
||||
if lines.peek().is_some() {
|
||||
self.chunks
|
||||
.seek(self.chunks.offset() + line.len() + "\n".len());
|
||||
return Some(&self.current_line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1355,6 +1371,21 @@ mod tests {
|
|||
assert_eq!(lines.next(), Some("hi"));
|
||||
assert_eq!(lines.next(), Some(""));
|
||||
assert_eq!(lines.next(), None);
|
||||
|
||||
let rope = Rope::from("abc\ndefg\nhi");
|
||||
let mut lines = rope.reversed_chunks_in_range(0..rope.len()).lines();
|
||||
assert_eq!(lines.next(), Some("hi"));
|
||||
assert_eq!(lines.next(), Some("defg"));
|
||||
assert_eq!(lines.next(), Some("abc"));
|
||||
assert_eq!(lines.next(), None);
|
||||
|
||||
let rope = Rope::from("abc\ndefg\nhi\n");
|
||||
let mut lines = rope.reversed_chunks_in_range(0..rope.len()).lines();
|
||||
assert_eq!(lines.next(), Some(""));
|
||||
assert_eq!(lines.next(), Some("hi"));
|
||||
assert_eq!(lines.next(), Some("defg"));
|
||||
assert_eq!(lines.next(), Some("abc"));
|
||||
assert_eq!(lines.next(), None);
|
||||
}
|
||||
|
||||
#[gpui::test(iterations = 100)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue