mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-05 02:20:10 +00:00
WIp
This commit is contained in:
parent
37a2ef9d41
commit
e0f553c0f5
3 changed files with 29 additions and 56 deletions
|
@ -746,7 +746,7 @@ impl DisplayRow {
|
|||
DisplayRow(display_row)
|
||||
}
|
||||
|
||||
pub fn to_line_span(&self, display_map: &DisplaySnapshot) -> Range<DisplayPoint> {
|
||||
pub fn to_points(&self, display_map: &DisplaySnapshot) -> Range<DisplayPoint> {
|
||||
self.start()..self.end(&display_map)
|
||||
}
|
||||
|
||||
|
@ -762,11 +762,6 @@ impl DisplayRow {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: Remove and use next_row
|
||||
fn next_unchecked(&self) -> Option<DisplayRow> {
|
||||
Some(DisplayRow(self.0 + 1))
|
||||
}
|
||||
|
||||
pub fn next_rows(
|
||||
&self,
|
||||
display_map: &DisplaySnapshot,
|
||||
|
@ -788,7 +783,7 @@ impl DisplayRow {
|
|||
if current == None {
|
||||
current = Some(start);
|
||||
} else {
|
||||
current = current.unwrap().next_unchecked();
|
||||
current = Some(DisplayRow(current.unwrap().0 + 1))
|
||||
}
|
||||
if current.unwrap().0 > end_row.0 {
|
||||
None
|
||||
|
|
|
@ -85,7 +85,7 @@ use std::{
|
|||
};
|
||||
pub use sum_tree::Bias;
|
||||
use theme::{DiagnosticStyle, Theme};
|
||||
use util::{post_inc, MapRangeEndsExt, RangeExt, ResultExt, TryFutureExt};
|
||||
use util::{post_inc, RangeExt, ResultExt, TryFutureExt};
|
||||
use workspace::{ItemNavHistory, ViewId, Workspace, WorkspaceId};
|
||||
|
||||
use crate::git::diff_hunk_to_display;
|
||||
|
@ -5738,7 +5738,7 @@ impl Editor {
|
|||
let fold_range = display_map
|
||||
.foldable_range(DisplayRow::new(row))
|
||||
.map(|range| {
|
||||
range.map_range(|display_point| display_point.to_point(&display_map))
|
||||
range.start.to_point(&display_map)..range.end.to_point(&display_map)
|
||||
});
|
||||
|
||||
if let Some(fold_range) = fold_range {
|
||||
|
@ -5761,29 +5761,23 @@ impl Editor {
|
|||
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
||||
|
||||
if let Some(fold_range) = display_map.foldable_range(display_row) {
|
||||
let autoscroll = self.selections_intersect(&fold_range, &display_map, cx);
|
||||
let autoscroll = {
|
||||
let selections = self.selections.all::<Point>(cx);
|
||||
|
||||
let point_range =
|
||||
fold_range.map_range(|display_point| display_point.to_point(&display_map));
|
||||
selections.iter().any(|selection| {
|
||||
let display_range = selection.display_range(&display_map);
|
||||
|
||||
self.fold_ranges(std::iter::once(point_range), autoscroll, cx);
|
||||
fold_range.overlaps(&display_range)
|
||||
})
|
||||
};
|
||||
|
||||
let fold_range =
|
||||
fold_range.start.to_point(&display_map)..fold_range.end.to_point(&display_map);
|
||||
|
||||
self.fold_ranges(std::iter::once(fold_range), autoscroll, cx);
|
||||
}
|
||||
}
|
||||
|
||||
fn selections_intersect(
|
||||
&mut self,
|
||||
range: &Range<DisplayPoint>,
|
||||
display_map: &DisplaySnapshot,
|
||||
cx: &mut ViewContext<Editor>,
|
||||
) -> bool {
|
||||
let selections = self.selections.all::<Point>(cx);
|
||||
|
||||
selections.iter().any(|selection| {
|
||||
let display_range = selection.display_range(display_map);
|
||||
range.contains(&display_range.start) || range.contains(&display_range.end)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn unfold_lines(&mut self, _: &UnfoldLines, cx: &mut ViewContext<Self>) {
|
||||
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
||||
let buffer = &display_map.buffer_snapshot;
|
||||
|
@ -5805,12 +5799,19 @@ impl Editor {
|
|||
pub fn unfold_at(&mut self, fold_at: &UnfoldAt, cx: &mut ViewContext<Self>) {
|
||||
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
|
||||
|
||||
let unfold_range = fold_at.display_row.to_line_span(&display_map);
|
||||
let unfold_range = fold_at.display_row.to_points(&display_map);
|
||||
|
||||
let autoscroll = self.selections_intersect(&unfold_range, &display_map, cx);
|
||||
let autoscroll = {
|
||||
let selections = self.selections.all::<Point>(cx);
|
||||
selections.iter().any(|selection| {
|
||||
let display_range = selection.display_range(&display_map);
|
||||
|
||||
let unfold_range = unfold_range.map_range(|endpoint| endpoint.to_point(&display_map));
|
||||
unfold_range.overlaps(&display_range)
|
||||
})
|
||||
};
|
||||
|
||||
let unfold_range =
|
||||
unfold_range.start.to_point(&display_map)..unfold_range.end.to_point(&display_map);
|
||||
self.unfold_ranges(std::iter::once(unfold_range), true, autoscroll, cx)
|
||||
}
|
||||
|
||||
|
|
|
@ -145,23 +145,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub trait MapRangeEndsExt<R> {
|
||||
fn map_range<T, F>(self, f: F) -> Range<T>
|
||||
where
|
||||
Self: Sized,
|
||||
F: Fn(R) -> T;
|
||||
}
|
||||
|
||||
impl<R> MapRangeEndsExt<R> for Range<R> {
|
||||
fn map_range<T, F>(self, f: F) -> Range<T>
|
||||
where
|
||||
Self: Sized,
|
||||
F: Fn(R) -> T,
|
||||
{
|
||||
f(self.start)..f(self.end)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LogErrorFuture<F>(F, log::Level);
|
||||
|
||||
impl<F, T> Future for LogErrorFuture<F>
|
||||
|
@ -254,7 +237,7 @@ macro_rules! iife {
|
|||
};
|
||||
}
|
||||
|
||||
/// Async lImmediately invoked function expression. Good for using the ? operator
|
||||
/// Async Immediately invoked function expression. Good for using the ? operator
|
||||
/// in functions which do not return an Option or Result. Async version of above
|
||||
#[macro_export]
|
||||
macro_rules! async_iife {
|
||||
|
@ -279,10 +262,7 @@ impl<T: Ord + Clone> RangeExt<T> for Range<T> {
|
|||
}
|
||||
|
||||
fn overlaps(&self, other: &Range<T>) -> bool {
|
||||
self.contains(&other.start)
|
||||
|| self.contains(&other.end)
|
||||
|| other.contains(&self.start)
|
||||
|| other.contains(&self.end)
|
||||
self.start < other.end && other.start < self.end
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -296,10 +276,7 @@ impl<T: Ord + Clone> RangeExt<T> for RangeInclusive<T> {
|
|||
}
|
||||
|
||||
fn overlaps(&self, other: &Range<T>) -> bool {
|
||||
self.contains(&other.start)
|
||||
|| self.contains(&other.end)
|
||||
|| other.contains(&self.start())
|
||||
|| other.contains(&self.end())
|
||||
self.start() < &other.end && &other.start <= self.end()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue