mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-12 05:15:00 +00:00
Misc fixes, still broken soft wrap
This commit is contained in:
parent
e75dcc853b
commit
a6a7e85894
1 changed files with 34 additions and 16 deletions
|
@ -48,6 +48,7 @@ use std::{
|
||||||
};
|
};
|
||||||
use theme::DiffStyle;
|
use theme::DiffStyle;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
struct DiffHunkLayout {
|
struct DiffHunkLayout {
|
||||||
visual_range: Range<u32>,
|
visual_range: Range<u32>,
|
||||||
status: DiffHunkStatus,
|
status: DiffHunkStatus,
|
||||||
|
@ -995,18 +996,26 @@ impl EditorElement {
|
||||||
.width()
|
.width()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-> (layout, buffer row advancement)
|
||||||
fn layout_diff_hunk(
|
fn layout_diff_hunk(
|
||||||
hunk: &DiffHunk<u32>,
|
hunk: &DiffHunk<u32>,
|
||||||
start_row: u32,
|
start_row: u32,
|
||||||
buffer_rows: &mut std::iter::Peekable<impl Iterator<Item = (usize, Option<u32>)>>,
|
buffer_rows: &mut std::iter::Peekable<impl Iterator<Item = (usize, Option<u32>)>>,
|
||||||
) -> DiffHunkLayout {
|
) -> (Option<DiffHunkLayout>, u32) {
|
||||||
//`buffer_rows` should start with a row which is contained in the hunk's buffer range
|
//`buffer_rows` should start with a row which is contained in the hunk's buffer range
|
||||||
|
let first_buffer_rows = match buffer_rows.peek() {
|
||||||
|
Some(first_buffer_rows) => first_buffer_rows,
|
||||||
|
None => return (None, 0),
|
||||||
|
};
|
||||||
|
|
||||||
//The `usize` field is 1-index so we have to sub to move it into 0-offset to match actual rows
|
//The `usize` field is 1-index so we have to sub to move it into 0-offset to match actual rows
|
||||||
let visual_start = start_row + buffer_rows.peek().unwrap().0 as u32 - 1;
|
let visual_start = start_row + first_buffer_rows.0 as u32 - 1;
|
||||||
|
|
||||||
let mut visual_count = 0;
|
let mut visual_count = 0;
|
||||||
|
let mut buffer_row_advancement = 0;
|
||||||
while let Some(&buffer_row) = buffer_rows.peek() {
|
while let Some(&buffer_row) = buffer_rows.peek() {
|
||||||
if let (_, Some(buffer_row)) = buffer_row {
|
if let (_, Some(buffer_row)) = buffer_row {
|
||||||
|
buffer_row_advancement += 1;
|
||||||
if buffer_row == hunk.buffer_range.end {
|
if buffer_row == hunk.buffer_range.end {
|
||||||
visual_count += 1;
|
visual_count += 1;
|
||||||
break;
|
break;
|
||||||
|
@ -1014,14 +1023,16 @@ impl EditorElement {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
visual_count += 1;
|
visual_count += 1;
|
||||||
buffer_rows.next();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DiffHunkLayout {
|
buffer_rows.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
let layout = DiffHunkLayout {
|
||||||
visual_range: visual_start..visual_start + visual_count,
|
visual_range: visual_start..visual_start + visual_count,
|
||||||
status: hunk.status(),
|
status: hunk.status(),
|
||||||
}
|
};
|
||||||
|
(Some(layout), buffer_row_advancement)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Folds contained in a hunk are ignored apart from shrinking visual size
|
//Folds contained in a hunk are ignored apart from shrinking visual size
|
||||||
|
@ -1048,10 +1059,15 @@ impl EditorElement {
|
||||||
let mut previous_buffer_row = None;
|
let mut previous_buffer_row = None;
|
||||||
|
|
||||||
while let Some((idx, buffer_row)) = buffer_rows.next() {
|
while let Some((idx, buffer_row)) = buffer_rows.next() {
|
||||||
let buffer_row = buffer_row.unwrap();
|
let buffer_row = match buffer_row {
|
||||||
|
Some(buffer_row) => buffer_row,
|
||||||
|
None => continue,
|
||||||
|
};
|
||||||
|
|
||||||
let is_start_of_fold = previous_buffer_row
|
let is_start_of_fold = previous_buffer_row
|
||||||
.map(|prev| buffer_row > prev + 1)
|
.map(|prev| buffer_row > prev + 1)
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
|
previous_buffer_row = Some(buffer_row);
|
||||||
|
|
||||||
if is_start_of_fold {
|
if is_start_of_fold {
|
||||||
//Consume all hunks within fold
|
//Consume all hunks within fold
|
||||||
|
@ -1077,21 +1093,23 @@ impl EditorElement {
|
||||||
status: DiffHunkStatus::Modified,
|
status: DiffHunkStatus::Modified,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else if let Some(hunk) = diff_hunks.peek() {
|
||||||
//Not the start of a fold
|
let row_inside_hunk = hunk.buffer_range.contains(&buffer_row);
|
||||||
if let Some(hunk) = diff_hunks.peek() {
|
let starts_on_row = hunk.buffer_range.start == buffer_row;
|
||||||
if hunk.buffer_range.contains(&buffer_row)
|
if row_inside_hunk || starts_on_row {
|
||||||
|| hunk.buffer_range.start == buffer_row
|
let (layout, buffer_row_advancement) =
|
||||||
{
|
Self::layout_diff_hunk(hunk, rows.start, &mut buffer_rows);
|
||||||
layouts.push(Self::layout_diff_hunk(hunk, rows.start, &mut buffer_rows));
|
previous_buffer_row = Some(buffer_row + buffer_row_advancement);
|
||||||
|
|
||||||
|
if let Some(layout) = layout {
|
||||||
|
layouts.push(layout);
|
||||||
|
}
|
||||||
|
|
||||||
diff_hunks.next();
|
diff_hunks.next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
previous_buffer_row = Some(buffer_row);
|
|
||||||
}
|
|
||||||
|
|
||||||
layouts
|
layouts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue