Introduce DisplayRow, MultiBufferRow newtypes and BufferRow type alias (#11656)
Part of https://github.com/zed-industries/zed/issues/8081 To avoid confusion and bugs when converting between various row `u32`'s, use different types for each. Further PRs should split `Point` into buffer and multi buffer variants and make the code more readable. Release Notes: - N/A --------- Co-authored-by: Piotr <piotr@zed.dev>
This commit is contained in:
parent
38f110852f
commit
df41435d1a
46 changed files with 1726 additions and 1220 deletions
|
@ -910,7 +910,7 @@ mod tests {
|
|||
use super::*;
|
||||
use assets::Assets;
|
||||
use collections::HashSet;
|
||||
use editor::{scroll::Autoscroll, DisplayPoint, Editor};
|
||||
use editor::{display_map::DisplayRow, scroll::Autoscroll, DisplayPoint, Editor};
|
||||
use gpui::{
|
||||
actions, Action, AnyWindowHandle, AppContext, AssetSource, BorrowAppContext, Entity,
|
||||
TestAppContext, VisualTestContext, WindowHandle,
|
||||
|
@ -2229,9 +2229,8 @@ mod tests {
|
|||
.update(cx, |_, cx| {
|
||||
editor1.update(cx, |editor, cx| {
|
||||
editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
|
||||
s.select_display_ranges(
|
||||
[DisplayPoint::new(10, 0)..DisplayPoint::new(10, 0)],
|
||||
)
|
||||
s.select_display_ranges([DisplayPoint::new(DisplayRow(10), 0)
|
||||
..DisplayPoint::new(DisplayRow(10), 0)])
|
||||
});
|
||||
});
|
||||
})
|
||||
|
@ -2256,9 +2255,8 @@ mod tests {
|
|||
.update(cx, |_, cx| {
|
||||
editor3.update(cx, |editor, cx| {
|
||||
editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
|
||||
s.select_display_ranges(
|
||||
[DisplayPoint::new(12, 0)..DisplayPoint::new(12, 0)],
|
||||
)
|
||||
s.select_display_ranges([DisplayPoint::new(DisplayRow(12), 0)
|
||||
..DisplayPoint::new(DisplayRow(12), 0)])
|
||||
});
|
||||
editor.newline(&Default::default(), cx);
|
||||
editor.newline(&Default::default(), cx);
|
||||
|
@ -2279,7 +2277,7 @@ mod tests {
|
|||
.unwrap();
|
||||
assert_eq!(
|
||||
active_location(&workspace, cx),
|
||||
(file3.clone(), DisplayPoint::new(16, 0), 12.5)
|
||||
(file3.clone(), DisplayPoint::new(DisplayRow(16), 0), 12.5)
|
||||
);
|
||||
|
||||
workspace
|
||||
|
@ -2289,7 +2287,7 @@ mod tests {
|
|||
.unwrap();
|
||||
assert_eq!(
|
||||
active_location(&workspace, cx),
|
||||
(file3.clone(), DisplayPoint::new(0, 0), 0.)
|
||||
(file3.clone(), DisplayPoint::new(DisplayRow(0), 0), 0.)
|
||||
);
|
||||
|
||||
workspace
|
||||
|
@ -2299,7 +2297,7 @@ mod tests {
|
|||
.unwrap();
|
||||
assert_eq!(
|
||||
active_location(&workspace, cx),
|
||||
(file2.clone(), DisplayPoint::new(0, 0), 0.)
|
||||
(file2.clone(), DisplayPoint::new(DisplayRow(0), 0), 0.)
|
||||
);
|
||||
|
||||
workspace
|
||||
|
@ -2309,7 +2307,7 @@ mod tests {
|
|||
.unwrap();
|
||||
assert_eq!(
|
||||
active_location(&workspace, cx),
|
||||
(file1.clone(), DisplayPoint::new(10, 0), 0.)
|
||||
(file1.clone(), DisplayPoint::new(DisplayRow(10), 0), 0.)
|
||||
);
|
||||
|
||||
workspace
|
||||
|
@ -2319,7 +2317,7 @@ mod tests {
|
|||
.unwrap();
|
||||
assert_eq!(
|
||||
active_location(&workspace, cx),
|
||||
(file1.clone(), DisplayPoint::new(0, 0), 0.)
|
||||
(file1.clone(), DisplayPoint::new(DisplayRow(0), 0), 0.)
|
||||
);
|
||||
|
||||
// Go back one more time and ensure we don't navigate past the first item in the history.
|
||||
|
@ -2330,7 +2328,7 @@ mod tests {
|
|||
.unwrap();
|
||||
assert_eq!(
|
||||
active_location(&workspace, cx),
|
||||
(file1.clone(), DisplayPoint::new(0, 0), 0.)
|
||||
(file1.clone(), DisplayPoint::new(DisplayRow(0), 0), 0.)
|
||||
);
|
||||
|
||||
workspace
|
||||
|
@ -2340,7 +2338,7 @@ mod tests {
|
|||
.unwrap();
|
||||
assert_eq!(
|
||||
active_location(&workspace, cx),
|
||||
(file1.clone(), DisplayPoint::new(10, 0), 0.)
|
||||
(file1.clone(), DisplayPoint::new(DisplayRow(10), 0), 0.)
|
||||
);
|
||||
|
||||
workspace
|
||||
|
@ -2350,7 +2348,7 @@ mod tests {
|
|||
.unwrap();
|
||||
assert_eq!(
|
||||
active_location(&workspace, cx),
|
||||
(file2.clone(), DisplayPoint::new(0, 0), 0.)
|
||||
(file2.clone(), DisplayPoint::new(DisplayRow(0), 0), 0.)
|
||||
);
|
||||
|
||||
// Go forward to an item that has been closed, ensuring it gets re-opened at the same
|
||||
|
@ -2373,7 +2371,7 @@ mod tests {
|
|||
.unwrap();
|
||||
assert_eq!(
|
||||
active_location(&workspace, cx),
|
||||
(file3.clone(), DisplayPoint::new(0, 0), 0.)
|
||||
(file3.clone(), DisplayPoint::new(DisplayRow(0), 0), 0.)
|
||||
);
|
||||
|
||||
workspace
|
||||
|
@ -2383,7 +2381,7 @@ mod tests {
|
|||
.unwrap();
|
||||
assert_eq!(
|
||||
active_location(&workspace, cx),
|
||||
(file3.clone(), DisplayPoint::new(16, 0), 12.5)
|
||||
(file3.clone(), DisplayPoint::new(DisplayRow(16), 0), 12.5)
|
||||
);
|
||||
|
||||
workspace
|
||||
|
@ -2393,7 +2391,7 @@ mod tests {
|
|||
.unwrap();
|
||||
assert_eq!(
|
||||
active_location(&workspace, cx),
|
||||
(file3.clone(), DisplayPoint::new(0, 0), 0.)
|
||||
(file3.clone(), DisplayPoint::new(DisplayRow(0), 0), 0.)
|
||||
);
|
||||
|
||||
// Go back to an item that has been closed and removed from disk
|
||||
|
@ -2422,7 +2420,7 @@ mod tests {
|
|||
.unwrap();
|
||||
assert_eq!(
|
||||
active_location(&workspace, cx),
|
||||
(file2.clone(), DisplayPoint::new(0, 0), 0.)
|
||||
(file2.clone(), DisplayPoint::new(DisplayRow(0), 0), 0.)
|
||||
);
|
||||
workspace
|
||||
.update(cx, |w, cx| w.go_forward(w.active_pane().downgrade(), cx))
|
||||
|
@ -2431,7 +2429,7 @@ mod tests {
|
|||
.unwrap();
|
||||
assert_eq!(
|
||||
active_location(&workspace, cx),
|
||||
(file3.clone(), DisplayPoint::new(0, 0), 0.)
|
||||
(file3.clone(), DisplayPoint::new(DisplayRow(0), 0), 0.)
|
||||
);
|
||||
|
||||
// Modify file to collapse multiple nav history entries into the same location.
|
||||
|
@ -2440,9 +2438,8 @@ mod tests {
|
|||
.update(cx, |_, cx| {
|
||||
editor1.update(cx, |editor, cx| {
|
||||
editor.change_selections(None, cx, |s| {
|
||||
s.select_display_ranges(
|
||||
[DisplayPoint::new(15, 0)..DisplayPoint::new(15, 0)],
|
||||
)
|
||||
s.select_display_ranges([DisplayPoint::new(DisplayRow(15), 0)
|
||||
..DisplayPoint::new(DisplayRow(15), 0)])
|
||||
})
|
||||
});
|
||||
})
|
||||
|
@ -2452,9 +2449,8 @@ mod tests {
|
|||
.update(cx, |_, cx| {
|
||||
editor1.update(cx, |editor, cx| {
|
||||
editor.change_selections(None, cx, |s| {
|
||||
s.select_display_ranges([
|
||||
DisplayPoint::new(3, 0)..DisplayPoint::new(3, 0)
|
||||
])
|
||||
s.select_display_ranges([DisplayPoint::new(DisplayRow(3), 0)
|
||||
..DisplayPoint::new(DisplayRow(3), 0)])
|
||||
});
|
||||
});
|
||||
})
|
||||
|
@ -2464,9 +2460,8 @@ mod tests {
|
|||
.update(cx, |_, cx| {
|
||||
editor1.update(cx, |editor, cx| {
|
||||
editor.change_selections(None, cx, |s| {
|
||||
s.select_display_ranges([
|
||||
DisplayPoint::new(13, 0)..DisplayPoint::new(13, 0)
|
||||
])
|
||||
s.select_display_ranges([DisplayPoint::new(DisplayRow(13), 0)
|
||||
..DisplayPoint::new(DisplayRow(13), 0)])
|
||||
})
|
||||
});
|
||||
})
|
||||
|
@ -2477,9 +2472,8 @@ mod tests {
|
|||
editor1.update(cx, |editor, cx| {
|
||||
editor.transact(cx, |editor, cx| {
|
||||
editor.change_selections(None, cx, |s| {
|
||||
s.select_display_ranges([
|
||||
DisplayPoint::new(2, 0)..DisplayPoint::new(14, 0)
|
||||
])
|
||||
s.select_display_ranges([DisplayPoint::new(DisplayRow(2), 0)
|
||||
..DisplayPoint::new(DisplayRow(14), 0)])
|
||||
});
|
||||
editor.insert("", cx);
|
||||
})
|
||||
|
@ -2491,7 +2485,8 @@ mod tests {
|
|||
.update(cx, |_, cx| {
|
||||
editor1.update(cx, |editor, cx| {
|
||||
editor.change_selections(None, cx, |s| {
|
||||
s.select_display_ranges([DisplayPoint::new(1, 0)..DisplayPoint::new(1, 0)])
|
||||
s.select_display_ranges([DisplayPoint::new(DisplayRow(1), 0)
|
||||
..DisplayPoint::new(DisplayRow(1), 0)])
|
||||
})
|
||||
});
|
||||
})
|
||||
|
@ -2503,7 +2498,7 @@ mod tests {
|
|||
.unwrap();
|
||||
assert_eq!(
|
||||
active_location(&workspace, cx),
|
||||
(file1.clone(), DisplayPoint::new(2, 0), 0.)
|
||||
(file1.clone(), DisplayPoint::new(DisplayRow(2), 0), 0.)
|
||||
);
|
||||
workspace
|
||||
.update(cx, |w, cx| w.go_back(w.active_pane().downgrade(), cx))
|
||||
|
@ -2512,7 +2507,7 @@ mod tests {
|
|||
.unwrap();
|
||||
assert_eq!(
|
||||
active_location(&workspace, cx),
|
||||
(file1.clone(), DisplayPoint::new(3, 0), 0.)
|
||||
(file1.clone(), DisplayPoint::new(DisplayRow(3), 0), 0.)
|
||||
);
|
||||
|
||||
fn active_location(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue