Merge branch 'main' into unborked-git-zed2-diagnostics-view
This commit is contained in:
@@ -31,7 +31,7 @@ pub use block_map::{
|
||||
BlockDisposition, BlockId, BlockProperties, BlockStyle, RenderBlock, TransformBlock,
|
||||
};
|
||||
|
||||
pub use self::fold_map::FoldPoint;
|
||||
pub use self::fold_map::{Fold, FoldPoint};
|
||||
pub use self::inlay_map::{Inlay, InlayOffset, InlayPoint};
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
@@ -124,7 +124,7 @@ impl DisplayMap {
|
||||
self.fold(
|
||||
other
|
||||
.folds_in_range(0..other.buffer_snapshot.len())
|
||||
.map(|fold| fold.to_offset(&other.buffer_snapshot)),
|
||||
.map(|fold| fold.range.to_offset(&other.buffer_snapshot)),
|
||||
cx,
|
||||
);
|
||||
}
|
||||
@@ -578,12 +578,7 @@ impl DisplaySnapshot {
|
||||
line.push_str(chunk.chunk);
|
||||
|
||||
let text_style = if let Some(style) = chunk.style {
|
||||
editor_style
|
||||
.text
|
||||
.clone()
|
||||
.highlight(style)
|
||||
.map(Cow::Owned)
|
||||
.unwrap_or_else(|_| Cow::Borrowed(&editor_style.text))
|
||||
Cow::Owned(editor_style.text.clone().highlight(style))
|
||||
} else {
|
||||
Cow::Borrowed(&editor_style.text)
|
||||
};
|
||||
@@ -728,7 +723,7 @@ impl DisplaySnapshot {
|
||||
DisplayPoint(point)
|
||||
}
|
||||
|
||||
pub fn folds_in_range<T>(&self, range: Range<T>) -> impl Iterator<Item = &Range<Anchor>>
|
||||
pub fn folds_in_range<T>(&self, range: Range<T>) -> impl Iterator<Item = &Fold>
|
||||
where
|
||||
T: ToOffset,
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@ use super::{
|
||||
wrap_map::{self, WrapEdit, WrapPoint, WrapSnapshot},
|
||||
Highlights,
|
||||
};
|
||||
use crate::{Anchor, Editor, ExcerptId, ExcerptRange, ToPoint as _};
|
||||
use crate::{Anchor, Editor, EditorStyle, ExcerptId, ExcerptRange, ToPoint as _};
|
||||
use collections::{Bound, HashMap, HashSet};
|
||||
use gpui::{AnyElement, Pixels, ViewContext};
|
||||
use language::{BufferSnapshot, Chunk, Patch, Point};
|
||||
@@ -88,6 +88,7 @@ pub struct BlockContext<'a, 'b> {
|
||||
pub em_width: Pixels,
|
||||
pub line_height: Pixels,
|
||||
pub block_id: usize,
|
||||
pub editor_style: &'b EditorStyle,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
|
||||
@@ -3,15 +3,16 @@ use super::{
|
||||
Highlights,
|
||||
};
|
||||
use crate::{Anchor, AnchorRangeExt, MultiBufferSnapshot, ToOffset};
|
||||
use gpui::{HighlightStyle, Hsla};
|
||||
use gpui::{ElementId, HighlightStyle, Hsla};
|
||||
use language::{Chunk, Edit, Point, TextSummary};
|
||||
use std::{
|
||||
any::TypeId,
|
||||
cmp::{self, Ordering},
|
||||
iter,
|
||||
ops::{Add, AddAssign, Range, Sub},
|
||||
ops::{Add, AddAssign, Deref, DerefMut, Range, Sub},
|
||||
};
|
||||
use sum_tree::{Bias, Cursor, FilterCursor, SumTree};
|
||||
use util::post_inc;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq)]
|
||||
pub struct FoldPoint(pub Point);
|
||||
@@ -90,12 +91,16 @@ impl<'a> FoldMapWriter<'a> {
|
||||
}
|
||||
|
||||
// For now, ignore any ranges that span an excerpt boundary.
|
||||
let fold = Fold(buffer.anchor_after(range.start)..buffer.anchor_before(range.end));
|
||||
if fold.0.start.excerpt_id != fold.0.end.excerpt_id {
|
||||
let fold_range =
|
||||
FoldRange(buffer.anchor_after(range.start)..buffer.anchor_before(range.end));
|
||||
if fold_range.0.start.excerpt_id != fold_range.0.end.excerpt_id {
|
||||
continue;
|
||||
}
|
||||
|
||||
folds.push(fold);
|
||||
folds.push(Fold {
|
||||
id: FoldId(post_inc(&mut self.0.next_fold_id.0)),
|
||||
range: fold_range,
|
||||
});
|
||||
|
||||
let inlay_range =
|
||||
snapshot.to_inlay_offset(range.start)..snapshot.to_inlay_offset(range.end);
|
||||
@@ -106,13 +111,13 @@ impl<'a> FoldMapWriter<'a> {
|
||||
}
|
||||
|
||||
let buffer = &snapshot.buffer;
|
||||
folds.sort_unstable_by(|a, b| sum_tree::SeekTarget::cmp(a, b, buffer));
|
||||
folds.sort_unstable_by(|a, b| sum_tree::SeekTarget::cmp(&a.range, &b.range, buffer));
|
||||
|
||||
self.0.snapshot.folds = {
|
||||
let mut new_tree = SumTree::new();
|
||||
let mut cursor = self.0.snapshot.folds.cursor::<Fold>();
|
||||
let mut cursor = self.0.snapshot.folds.cursor::<FoldRange>();
|
||||
for fold in folds {
|
||||
new_tree.append(cursor.slice(&fold, Bias::Right, buffer), buffer);
|
||||
new_tree.append(cursor.slice(&fold.range, Bias::Right, buffer), buffer);
|
||||
new_tree.push(fold, buffer);
|
||||
}
|
||||
new_tree.append(cursor.suffix(buffer), buffer);
|
||||
@@ -138,7 +143,8 @@ impl<'a> FoldMapWriter<'a> {
|
||||
let mut folds_cursor =
|
||||
intersecting_folds(&snapshot, &self.0.snapshot.folds, range, inclusive);
|
||||
while let Some(fold) = folds_cursor.item() {
|
||||
let offset_range = fold.0.start.to_offset(buffer)..fold.0.end.to_offset(buffer);
|
||||
let offset_range =
|
||||
fold.range.start.to_offset(buffer)..fold.range.end.to_offset(buffer);
|
||||
if offset_range.end > offset_range.start {
|
||||
let inlay_range = snapshot.to_inlay_offset(offset_range.start)
|
||||
..snapshot.to_inlay_offset(offset_range.end);
|
||||
@@ -175,6 +181,7 @@ impl<'a> FoldMapWriter<'a> {
|
||||
pub struct FoldMap {
|
||||
snapshot: FoldSnapshot,
|
||||
ellipses_color: Option<Hsla>,
|
||||
next_fold_id: FoldId,
|
||||
}
|
||||
|
||||
impl FoldMap {
|
||||
@@ -197,6 +204,7 @@ impl FoldMap {
|
||||
ellipses_color: None,
|
||||
},
|
||||
ellipses_color: None,
|
||||
next_fold_id: FoldId::default(),
|
||||
};
|
||||
let snapshot = this.snapshot.clone();
|
||||
(this, snapshot)
|
||||
@@ -242,8 +250,8 @@ impl FoldMap {
|
||||
while let Some(fold) = folds.next() {
|
||||
if let Some(next_fold) = folds.peek() {
|
||||
let comparison = fold
|
||||
.0
|
||||
.cmp(&next_fold.0, &self.snapshot.inlay_snapshot.buffer);
|
||||
.range
|
||||
.cmp(&next_fold.range, &self.snapshot.inlay_snapshot.buffer);
|
||||
assert!(comparison.is_le());
|
||||
}
|
||||
}
|
||||
@@ -304,9 +312,9 @@ impl FoldMap {
|
||||
let anchor = inlay_snapshot
|
||||
.buffer
|
||||
.anchor_before(inlay_snapshot.to_buffer_offset(edit.new.start));
|
||||
let mut folds_cursor = self.snapshot.folds.cursor::<Fold>();
|
||||
let mut folds_cursor = self.snapshot.folds.cursor::<FoldRange>();
|
||||
folds_cursor.seek(
|
||||
&Fold(anchor..Anchor::max()),
|
||||
&FoldRange(anchor..Anchor::max()),
|
||||
Bias::Left,
|
||||
&inlay_snapshot.buffer,
|
||||
);
|
||||
@@ -315,8 +323,8 @@ impl FoldMap {
|
||||
let inlay_snapshot = &inlay_snapshot;
|
||||
move || {
|
||||
let item = folds_cursor.item().map(|f| {
|
||||
let buffer_start = f.0.start.to_offset(&inlay_snapshot.buffer);
|
||||
let buffer_end = f.0.end.to_offset(&inlay_snapshot.buffer);
|
||||
let buffer_start = f.range.start.to_offset(&inlay_snapshot.buffer);
|
||||
let buffer_end = f.range.end.to_offset(&inlay_snapshot.buffer);
|
||||
inlay_snapshot.to_inlay_offset(buffer_start)
|
||||
..inlay_snapshot.to_inlay_offset(buffer_end)
|
||||
});
|
||||
@@ -596,13 +604,13 @@ impl FoldSnapshot {
|
||||
self.transforms.summary().output.longest_row
|
||||
}
|
||||
|
||||
pub fn folds_in_range<T>(&self, range: Range<T>) -> impl Iterator<Item = &Range<Anchor>>
|
||||
pub fn folds_in_range<T>(&self, range: Range<T>) -> impl Iterator<Item = &Fold>
|
||||
where
|
||||
T: ToOffset,
|
||||
{
|
||||
let mut folds = intersecting_folds(&self.inlay_snapshot, &self.folds, range, false);
|
||||
iter::from_fn(move || {
|
||||
let item = folds.item().map(|f| &f.0);
|
||||
let item = folds.item();
|
||||
folds.next(&self.inlay_snapshot.buffer);
|
||||
item
|
||||
})
|
||||
@@ -830,10 +838,39 @@ impl sum_tree::Summary for TransformSummary {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Fold(Range<Anchor>);
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Debug, Default)]
|
||||
pub struct FoldId(usize);
|
||||
|
||||
impl Default for Fold {
|
||||
impl Into<ElementId> for FoldId {
|
||||
fn into(self) -> ElementId {
|
||||
ElementId::Integer(self.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct Fold {
|
||||
pub id: FoldId,
|
||||
pub range: FoldRange,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct FoldRange(Range<Anchor>);
|
||||
|
||||
impl Deref for FoldRange {
|
||||
type Target = Range<Anchor>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for FoldRange {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for FoldRange {
|
||||
fn default() -> Self {
|
||||
Self(Anchor::min()..Anchor::max())
|
||||
}
|
||||
@@ -844,17 +881,17 @@ impl sum_tree::Item for Fold {
|
||||
|
||||
fn summary(&self) -> Self::Summary {
|
||||
FoldSummary {
|
||||
start: self.0.start.clone(),
|
||||
end: self.0.end.clone(),
|
||||
min_start: self.0.start.clone(),
|
||||
max_end: self.0.end.clone(),
|
||||
start: self.range.start.clone(),
|
||||
end: self.range.end.clone(),
|
||||
min_start: self.range.start.clone(),
|
||||
max_end: self.range.end.clone(),
|
||||
count: 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct FoldSummary {
|
||||
pub struct FoldSummary {
|
||||
start: Anchor,
|
||||
end: Anchor,
|
||||
min_start: Anchor,
|
||||
@@ -900,14 +937,14 @@ impl sum_tree::Summary for FoldSummary {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, FoldSummary> for Fold {
|
||||
impl<'a> sum_tree::Dimension<'a, FoldSummary> for FoldRange {
|
||||
fn add_summary(&mut self, summary: &'a FoldSummary, _: &MultiBufferSnapshot) {
|
||||
self.0.start = summary.start.clone();
|
||||
self.0.end = summary.end.clone();
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> sum_tree::SeekTarget<'a, FoldSummary, Fold> for Fold {
|
||||
impl<'a> sum_tree::SeekTarget<'a, FoldSummary, FoldRange> for FoldRange {
|
||||
fn cmp(&self, other: &Self, buffer: &MultiBufferSnapshot) -> Ordering {
|
||||
self.0.cmp(&other.0, buffer)
|
||||
}
|
||||
@@ -1321,7 +1358,10 @@ mod tests {
|
||||
let (snapshot, _) = map.read(inlay_snapshot.clone(), vec![]);
|
||||
let fold_ranges = snapshot
|
||||
.folds_in_range(Point::new(1, 0)..Point::new(1, 3))
|
||||
.map(|fold| fold.start.to_point(&buffer_snapshot)..fold.end.to_point(&buffer_snapshot))
|
||||
.map(|fold| {
|
||||
fold.range.start.to_point(&buffer_snapshot)
|
||||
..fold.range.end.to_point(&buffer_snapshot)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(
|
||||
fold_ranges,
|
||||
@@ -1553,10 +1593,9 @@ mod tests {
|
||||
.filter(|fold| {
|
||||
let start = buffer_snapshot.anchor_before(start);
|
||||
let end = buffer_snapshot.anchor_after(end);
|
||||
start.cmp(&fold.0.end, &buffer_snapshot) == Ordering::Less
|
||||
&& end.cmp(&fold.0.start, &buffer_snapshot) == Ordering::Greater
|
||||
start.cmp(&fold.range.end, &buffer_snapshot) == Ordering::Less
|
||||
&& end.cmp(&fold.range.start, &buffer_snapshot) == Ordering::Greater
|
||||
})
|
||||
.map(|fold| fold.0)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
assert_eq!(
|
||||
@@ -1639,10 +1678,10 @@ mod tests {
|
||||
let buffer = &inlay_snapshot.buffer;
|
||||
let mut folds = self.snapshot.folds.items(buffer);
|
||||
// Ensure sorting doesn't change how folds get merged and displayed.
|
||||
folds.sort_by(|a, b| a.0.cmp(&b.0, buffer));
|
||||
folds.sort_by(|a, b| a.range.cmp(&b.range, buffer));
|
||||
let mut fold_ranges = folds
|
||||
.iter()
|
||||
.map(|fold| fold.0.start.to_offset(buffer)..fold.0.end.to_offset(buffer))
|
||||
.map(|fold| fold.range.start.to_offset(buffer)..fold.range.end.to_offset(buffer))
|
||||
.peekable();
|
||||
|
||||
let mut merged_ranges = Vec::new();
|
||||
|
||||
+237
-244
@@ -100,7 +100,9 @@ use theme::{
|
||||
use ui::{v_stack, HighlightedLabel, IconButton, StyledExt, TextTooltip};
|
||||
use util::{post_inc, RangeExt, ResultExt, TryFutureExt};
|
||||
use workspace::{
|
||||
item::ItemEvent, searchable::SearchEvent, ItemNavHistory, SplitDirection, ViewId, Workspace,
|
||||
item::{ItemEvent, ItemHandle},
|
||||
searchable::SearchEvent,
|
||||
ItemNavHistory, SplitDirection, ViewId, Workspace,
|
||||
};
|
||||
|
||||
const CURSOR_BLINK_INTERVAL: Duration = Duration::from_millis(500);
|
||||
@@ -1878,10 +1880,8 @@ impl Editor {
|
||||
);
|
||||
|
||||
let focus_handle = cx.focus_handle();
|
||||
cx.on_focus_in(&focus_handle, Self::handle_focus_in)
|
||||
.detach();
|
||||
cx.on_focus_out(&focus_handle, Self::handle_focus_out)
|
||||
.detach();
|
||||
cx.on_focus(&focus_handle, Self::handle_focus).detach();
|
||||
cx.on_blur(&focus_handle, Self::handle_blur).detach();
|
||||
|
||||
let mut this = Self {
|
||||
handle: cx.view().downgrade(),
|
||||
@@ -4372,69 +4372,42 @@ impl Editor {
|
||||
}
|
||||
}
|
||||
|
||||
// pub fn render_fold_indicators(
|
||||
// &self,
|
||||
// fold_data: Vec<Option<(FoldStatus, u32, bool)>>,
|
||||
// style: &EditorStyle,
|
||||
// gutter_hovered: bool,
|
||||
// line_height: f32,
|
||||
// gutter_margin: f32,
|
||||
// cx: &mut ViewContext<Self>,
|
||||
// ) -> Vec<Option<AnyElement<Self>>> {
|
||||
// enum FoldIndicators {}
|
||||
|
||||
// let style = style.folds.clone();
|
||||
|
||||
// fold_data
|
||||
// .iter()
|
||||
// .enumerate()
|
||||
// .map(|(ix, fold_data)| {
|
||||
// fold_data
|
||||
// .map(|(fold_status, buffer_row, active)| {
|
||||
// (active || gutter_hovered || fold_status == FoldStatus::Folded).then(|| {
|
||||
// MouseEventHandler::new::<FoldIndicators, _>(
|
||||
// ix as usize,
|
||||
// cx,
|
||||
// |mouse_state, _| {
|
||||
// Svg::new(match fold_status {
|
||||
// FoldStatus::Folded => style.folded_icon.clone(),
|
||||
// FoldStatus::Foldable => style.foldable_icon.clone(),
|
||||
// })
|
||||
// .with_color(
|
||||
// style
|
||||
// .indicator
|
||||
// .in_state(fold_status == FoldStatus::Folded)
|
||||
// .style_for(mouse_state)
|
||||
// .color,
|
||||
// )
|
||||
// .constrained()
|
||||
// .with_width(gutter_margin * style.icon_margin_scale)
|
||||
// .aligned()
|
||||
// .constrained()
|
||||
// .with_height(line_height)
|
||||
// .with_width(gutter_margin)
|
||||
// .aligned()
|
||||
// },
|
||||
// )
|
||||
// .with_cursor_style(CursorStyle::PointingHand)
|
||||
// .with_padding(Padding::uniform(3.))
|
||||
// .on_click(MouseButton::Left, {
|
||||
// move |_, editor, cx| match fold_status {
|
||||
// FoldStatus::Folded => {
|
||||
// editor.unfold_at(&UnfoldAt { buffer_row }, cx);
|
||||
// }
|
||||
// FoldStatus::Foldable => {
|
||||
// editor.fold_at(&FoldAt { buffer_row }, cx);
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// .into_any()
|
||||
// })
|
||||
// })
|
||||
// .flatten()
|
||||
// })
|
||||
// .collect()
|
||||
// }
|
||||
pub fn render_fold_indicators(
|
||||
&self,
|
||||
fold_data: Vec<Option<(FoldStatus, u32, bool)>>,
|
||||
style: &EditorStyle,
|
||||
gutter_hovered: bool,
|
||||
line_height: Pixels,
|
||||
gutter_margin: Pixels,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Vec<Option<AnyElement<Self>>> {
|
||||
fold_data
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(ix, fold_data)| {
|
||||
fold_data
|
||||
.map(|(fold_status, buffer_row, active)| {
|
||||
(active || gutter_hovered || fold_status == FoldStatus::Folded).then(|| {
|
||||
let icon = match fold_status {
|
||||
FoldStatus::Folded => ui::Icon::ChevronRight,
|
||||
FoldStatus::Foldable => ui::Icon::ChevronDown,
|
||||
};
|
||||
IconButton::new(ix as usize, icon)
|
||||
.on_click(move |editor: &mut Editor, cx| match fold_status {
|
||||
FoldStatus::Folded => {
|
||||
editor.unfold_at(&UnfoldAt { buffer_row }, cx);
|
||||
}
|
||||
FoldStatus::Foldable => {
|
||||
editor.fold_at(&FoldAt { buffer_row }, cx);
|
||||
}
|
||||
})
|
||||
.render()
|
||||
})
|
||||
})
|
||||
.flatten()
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn context_menu_visible(&self) -> bool {
|
||||
self.context_menu
|
||||
@@ -5330,8 +5303,8 @@ impl Editor {
|
||||
buffer.anchor_before(range_to_move.start)
|
||||
..buffer.anchor_after(range_to_move.end),
|
||||
) {
|
||||
let mut start = fold.start.to_point(&buffer);
|
||||
let mut end = fold.end.to_point(&buffer);
|
||||
let mut start = fold.range.start.to_point(&buffer);
|
||||
let mut end = fold.range.end.to_point(&buffer);
|
||||
start.row -= row_delta;
|
||||
end.row -= row_delta;
|
||||
refold_ranges.push(start..end);
|
||||
@@ -5421,8 +5394,8 @@ impl Editor {
|
||||
buffer.anchor_before(range_to_move.start)
|
||||
..buffer.anchor_after(range_to_move.end),
|
||||
) {
|
||||
let mut start = fold.start.to_point(&buffer);
|
||||
let mut end = fold.end.to_point(&buffer);
|
||||
let mut start = fold.range.start.to_point(&buffer);
|
||||
let mut end = fold.range.end.to_point(&buffer);
|
||||
start.row += row_delta;
|
||||
end.row += row_delta;
|
||||
refold_ranges.push(start..end);
|
||||
@@ -7690,183 +7663,203 @@ impl Editor {
|
||||
}
|
||||
}
|
||||
|
||||
// pub fn rename(&mut self, _: &Rename, cx: &mut ViewContext<Self>) -> Option<Task<Result<()>>> {
|
||||
// use language::ToOffset as _;
|
||||
pub fn rename(&mut self, _: &Rename, cx: &mut ViewContext<Self>) -> Option<Task<Result<()>>> {
|
||||
use language::ToOffset as _;
|
||||
|
||||
// let project = self.project.clone()?;
|
||||
// let selection = self.selections.newest_anchor().clone();
|
||||
// let (cursor_buffer, cursor_buffer_position) = self
|
||||
// .buffer
|
||||
// .read(cx)
|
||||
// .text_anchor_for_position(selection.head(), cx)?;
|
||||
// let (tail_buffer, _) = self
|
||||
// .buffer
|
||||
// .read(cx)
|
||||
// .text_anchor_for_position(selection.tail(), cx)?;
|
||||
// if tail_buffer != cursor_buffer {
|
||||
// return None;
|
||||
// }
|
||||
let project = self.project.clone()?;
|
||||
let selection = self.selections.newest_anchor().clone();
|
||||
let (cursor_buffer, cursor_buffer_position) = self
|
||||
.buffer
|
||||
.read(cx)
|
||||
.text_anchor_for_position(selection.head(), cx)?;
|
||||
let (tail_buffer, _) = self
|
||||
.buffer
|
||||
.read(cx)
|
||||
.text_anchor_for_position(selection.tail(), cx)?;
|
||||
if tail_buffer != cursor_buffer {
|
||||
return None;
|
||||
}
|
||||
|
||||
// let snapshot = cursor_buffer.read(cx).snapshot();
|
||||
// let cursor_buffer_offset = cursor_buffer_position.to_offset(&snapshot);
|
||||
// let prepare_rename = project.update(cx, |project, cx| {
|
||||
// project.prepare_rename(cursor_buffer, cursor_buffer_offset, cx)
|
||||
// });
|
||||
let snapshot = cursor_buffer.read(cx).snapshot();
|
||||
let cursor_buffer_offset = cursor_buffer_position.to_offset(&snapshot);
|
||||
let prepare_rename = project.update(cx, |project, cx| {
|
||||
project.prepare_rename(cursor_buffer, cursor_buffer_offset, cx)
|
||||
});
|
||||
|
||||
// Some(cx.spawn(|this, mut cx| async move {
|
||||
// let rename_range = if let Some(range) = prepare_rename.await? {
|
||||
// Some(range)
|
||||
// } else {
|
||||
// this.update(&mut cx, |this, cx| {
|
||||
// let buffer = this.buffer.read(cx).snapshot(cx);
|
||||
// let mut buffer_highlights = this
|
||||
// .document_highlights_for_position(selection.head(), &buffer)
|
||||
// .filter(|highlight| {
|
||||
// highlight.start.excerpt_id == selection.head().excerpt_id
|
||||
// && highlight.end.excerpt_id == selection.head().excerpt_id
|
||||
// });
|
||||
// buffer_highlights
|
||||
// .next()
|
||||
// .map(|highlight| highlight.start.text_anchor..highlight.end.text_anchor)
|
||||
// })?
|
||||
// };
|
||||
// if let Some(rename_range) = rename_range {
|
||||
// let rename_buffer_range = rename_range.to_offset(&snapshot);
|
||||
// let cursor_offset_in_rename_range =
|
||||
// cursor_buffer_offset.saturating_sub(rename_buffer_range.start);
|
||||
Some(cx.spawn(|this, mut cx| async move {
|
||||
let rename_range = if let Some(range) = prepare_rename.await? {
|
||||
Some(range)
|
||||
} else {
|
||||
this.update(&mut cx, |this, cx| {
|
||||
let buffer = this.buffer.read(cx).snapshot(cx);
|
||||
let mut buffer_highlights = this
|
||||
.document_highlights_for_position(selection.head(), &buffer)
|
||||
.filter(|highlight| {
|
||||
highlight.start.excerpt_id == selection.head().excerpt_id
|
||||
&& highlight.end.excerpt_id == selection.head().excerpt_id
|
||||
});
|
||||
buffer_highlights
|
||||
.next()
|
||||
.map(|highlight| highlight.start.text_anchor..highlight.end.text_anchor)
|
||||
})?
|
||||
};
|
||||
if let Some(rename_range) = rename_range {
|
||||
let rename_buffer_range = rename_range.to_offset(&snapshot);
|
||||
let cursor_offset_in_rename_range =
|
||||
cursor_buffer_offset.saturating_sub(rename_buffer_range.start);
|
||||
|
||||
// this.update(&mut cx, |this, cx| {
|
||||
// this.take_rename(false, cx);
|
||||
// let buffer = this.buffer.read(cx).read(cx);
|
||||
// let cursor_offset = selection.head().to_offset(&buffer);
|
||||
// let rename_start = cursor_offset.saturating_sub(cursor_offset_in_rename_range);
|
||||
// let rename_end = rename_start + rename_buffer_range.len();
|
||||
// let range = buffer.anchor_before(rename_start)..buffer.anchor_after(rename_end);
|
||||
// let mut old_highlight_id = None;
|
||||
// let old_name: Arc<str> = buffer
|
||||
// .chunks(rename_start..rename_end, true)
|
||||
// .map(|chunk| {
|
||||
// if old_highlight_id.is_none() {
|
||||
// old_highlight_id = chunk.syntax_highlight_id;
|
||||
// }
|
||||
// chunk.text
|
||||
// })
|
||||
// .collect::<String>()
|
||||
// .into();
|
||||
this.update(&mut cx, |this, cx| {
|
||||
this.take_rename(false, cx);
|
||||
let buffer = this.buffer.read(cx).read(cx);
|
||||
let cursor_offset = selection.head().to_offset(&buffer);
|
||||
let rename_start = cursor_offset.saturating_sub(cursor_offset_in_rename_range);
|
||||
let rename_end = rename_start + rename_buffer_range.len();
|
||||
let range = buffer.anchor_before(rename_start)..buffer.anchor_after(rename_end);
|
||||
let mut old_highlight_id = None;
|
||||
let old_name: Arc<str> = buffer
|
||||
.chunks(rename_start..rename_end, true)
|
||||
.map(|chunk| {
|
||||
if old_highlight_id.is_none() {
|
||||
old_highlight_id = chunk.syntax_highlight_id;
|
||||
}
|
||||
chunk.text
|
||||
})
|
||||
.collect::<String>()
|
||||
.into();
|
||||
|
||||
// drop(buffer);
|
||||
drop(buffer);
|
||||
|
||||
// // Position the selection in the rename editor so that it matches the current selection.
|
||||
// this.show_local_selections = false;
|
||||
// let rename_editor = cx.build_view(|cx| {
|
||||
// let mut editor = Editor::single_line(cx);
|
||||
// if let Some(old_highlight_id) = old_highlight_id {
|
||||
// editor.override_text_style =
|
||||
// Some(Box::new(move |style| old_highlight_id.style(&style.syntax)));
|
||||
// }
|
||||
// editor.buffer.update(cx, |buffer, cx| {
|
||||
// buffer.edit([(0..0, old_name.clone())], None, cx)
|
||||
// });
|
||||
// editor.select_all(&SelectAll, cx);
|
||||
// editor
|
||||
// });
|
||||
// Position the selection in the rename editor so that it matches the current selection.
|
||||
this.show_local_selections = false;
|
||||
let rename_editor = cx.build_view(|cx| {
|
||||
let mut editor = Editor::single_line(cx);
|
||||
editor.buffer.update(cx, |buffer, cx| {
|
||||
buffer.edit([(0..0, old_name.clone())], None, cx)
|
||||
});
|
||||
editor.select_all(&SelectAll, cx);
|
||||
editor
|
||||
});
|
||||
|
||||
// let ranges = this
|
||||
// .clear_background_highlights::<DocumentHighlightWrite>(cx)
|
||||
// .into_iter()
|
||||
// .flat_map(|(_, ranges)| ranges.into_iter())
|
||||
// .chain(
|
||||
// this.clear_background_highlights::<DocumentHighlightRead>(cx)
|
||||
// .into_iter()
|
||||
// .flat_map(|(_, ranges)| ranges.into_iter()),
|
||||
// )
|
||||
// .collect();
|
||||
let ranges = this
|
||||
.clear_background_highlights::<DocumentHighlightWrite>(cx)
|
||||
.into_iter()
|
||||
.flat_map(|(_, ranges)| ranges.into_iter())
|
||||
.chain(
|
||||
this.clear_background_highlights::<DocumentHighlightRead>(cx)
|
||||
.into_iter()
|
||||
.flat_map(|(_, ranges)| ranges.into_iter()),
|
||||
)
|
||||
.collect();
|
||||
|
||||
// this.highlight_text::<Rename>(
|
||||
// ranges,
|
||||
// HighlightStyle {
|
||||
// fade_out: Some(style.rename_fade),
|
||||
// ..Default::default()
|
||||
// },
|
||||
// cx,
|
||||
// );
|
||||
// cx.focus(&rename_editor);
|
||||
// let block_id = this.insert_blocks(
|
||||
// [BlockProperties {
|
||||
// style: BlockStyle::Flex,
|
||||
// position: range.start.clone(),
|
||||
// height: 1,
|
||||
// render: Arc::new({
|
||||
// let editor = rename_editor.clone();
|
||||
// move |cx: &mut BlockContext| {
|
||||
// ChildView::new(&editor, cx)
|
||||
// .contained()
|
||||
// .with_padding_left(cx.anchor_x)
|
||||
// .into_any()
|
||||
// }
|
||||
// }),
|
||||
// disposition: BlockDisposition::Below,
|
||||
// }],
|
||||
// Some(Autoscroll::fit()),
|
||||
// cx,
|
||||
// )[0];
|
||||
// this.pending_rename = Some(RenameState {
|
||||
// range,
|
||||
// old_name,
|
||||
// editor: rename_editor,
|
||||
// block_id,
|
||||
// });
|
||||
// })?;
|
||||
// }
|
||||
this.highlight_text::<Rename>(
|
||||
ranges,
|
||||
HighlightStyle {
|
||||
fade_out: Some(0.6),
|
||||
..Default::default()
|
||||
},
|
||||
cx,
|
||||
);
|
||||
let rename_focus_handle = rename_editor.focus_handle(cx);
|
||||
cx.focus(&rename_focus_handle);
|
||||
let block_id = this.insert_blocks(
|
||||
[BlockProperties {
|
||||
style: BlockStyle::Flex,
|
||||
position: range.start.clone(),
|
||||
height: 1,
|
||||
render: Arc::new({
|
||||
let rename_editor = rename_editor.clone();
|
||||
move |cx: &mut BlockContext| {
|
||||
let mut text_style = cx.editor_style.text.clone();
|
||||
if let Some(highlight_style) = old_highlight_id
|
||||
.and_then(|h| h.style(&cx.editor_style.syntax))
|
||||
{
|
||||
text_style = text_style.highlight(highlight_style);
|
||||
}
|
||||
div()
|
||||
.pl(cx.anchor_x)
|
||||
.child(rename_editor.render_with(EditorElement::new(
|
||||
&rename_editor,
|
||||
EditorStyle {
|
||||
background: cx.theme().system().transparent,
|
||||
local_player: cx.editor_style.local_player,
|
||||
text: text_style,
|
||||
scrollbar_width: cx.editor_style.scrollbar_width,
|
||||
syntax: cx.editor_style.syntax.clone(),
|
||||
diagnostic_style:
|
||||
cx.editor_style.diagnostic_style.clone(),
|
||||
},
|
||||
)))
|
||||
.render()
|
||||
}
|
||||
}),
|
||||
disposition: BlockDisposition::Below,
|
||||
}],
|
||||
Some(Autoscroll::fit()),
|
||||
cx,
|
||||
)[0];
|
||||
this.pending_rename = Some(RenameState {
|
||||
range,
|
||||
old_name,
|
||||
editor: rename_editor,
|
||||
block_id,
|
||||
});
|
||||
})?;
|
||||
}
|
||||
|
||||
// Ok(())
|
||||
// }))
|
||||
// }
|
||||
Ok(())
|
||||
}))
|
||||
}
|
||||
|
||||
// pub fn confirm_rename(
|
||||
// workspace: &mut Workspace,
|
||||
// _: &ConfirmRename,
|
||||
// cx: &mut ViewContext<Workspace>,
|
||||
// ) -> Option<Task<Result<()>>> {
|
||||
// let editor = workspace.active_item(cx)?.act_as::<Editor>(cx)?;
|
||||
pub fn confirm_rename(
|
||||
&mut self,
|
||||
_: &ConfirmRename,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Option<Task<Result<()>>> {
|
||||
let rename = self.take_rename(false, cx)?;
|
||||
let workspace = self.workspace()?;
|
||||
let (start_buffer, start) = self
|
||||
.buffer
|
||||
.read(cx)
|
||||
.text_anchor_for_position(rename.range.start.clone(), cx)?;
|
||||
let (end_buffer, end) = self
|
||||
.buffer
|
||||
.read(cx)
|
||||
.text_anchor_for_position(rename.range.end.clone(), cx)?;
|
||||
if start_buffer != end_buffer {
|
||||
return None;
|
||||
}
|
||||
|
||||
// let (buffer, range, old_name, new_name) = editor.update(cx, |editor, cx| {
|
||||
// let rename = editor.take_rename(false, cx)?;
|
||||
// let buffer = editor.buffer.read(cx);
|
||||
// let (start_buffer, start) =
|
||||
// buffer.text_anchor_for_position(rename.range.start.clone(), cx)?;
|
||||
// let (end_buffer, end) =
|
||||
// buffer.text_anchor_for_position(rename.range.end.clone(), cx)?;
|
||||
// if start_buffer == end_buffer {
|
||||
// let new_name = rename.editor.read(cx).text(cx);
|
||||
// Some((start_buffer, start..end, rename.old_name, new_name))
|
||||
// } else {
|
||||
// None
|
||||
// }
|
||||
// })?;
|
||||
let buffer = start_buffer;
|
||||
let range = start..end;
|
||||
let old_name = rename.old_name;
|
||||
let new_name = rename.editor.read(cx).text(cx);
|
||||
|
||||
// let rename = workspace.project().clone().update(cx, |project, cx| {
|
||||
// project.perform_rename(buffer.clone(), range.start, new_name.clone(), true, cx)
|
||||
// });
|
||||
let rename = workspace
|
||||
.read(cx)
|
||||
.project()
|
||||
.clone()
|
||||
.update(cx, |project, cx| {
|
||||
project.perform_rename(buffer.clone(), range.start, new_name.clone(), true, cx)
|
||||
});
|
||||
let workspace = workspace.downgrade();
|
||||
|
||||
// let editor = editor.downgrade();
|
||||
// Some(cx.spawn(|workspace, mut cx| async move {
|
||||
// let project_transaction = rename.await?;
|
||||
// Self::open_project_transaction(
|
||||
// &editor,
|
||||
// workspace,
|
||||
// project_transaction,
|
||||
// format!("Rename: {} → {}", old_name, new_name),
|
||||
// cx.clone(),
|
||||
// )
|
||||
// .await?;
|
||||
Some(cx.spawn(|editor, mut cx| async move {
|
||||
let project_transaction = rename.await?;
|
||||
Self::open_project_transaction(
|
||||
&editor,
|
||||
workspace,
|
||||
project_transaction,
|
||||
format!("Rename: {} → {}", old_name, new_name),
|
||||
cx.clone(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// editor.update(&mut cx, |editor, cx| {
|
||||
// editor.refresh_document_highlights(cx);
|
||||
// })?;
|
||||
// Ok(())
|
||||
// }))
|
||||
// }
|
||||
editor.update(&mut cx, |editor, cx| {
|
||||
editor.refresh_document_highlights(cx);
|
||||
})?;
|
||||
Ok(())
|
||||
}))
|
||||
}
|
||||
|
||||
fn take_rename(
|
||||
&mut self,
|
||||
@@ -7874,6 +7867,10 @@ impl Editor {
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Option<RenameState> {
|
||||
let rename = self.pending_rename.take()?;
|
||||
if rename.editor.focus_handle(cx).is_focused(cx) {
|
||||
cx.focus(&self.focus_handle);
|
||||
}
|
||||
|
||||
self.remove_blocks(
|
||||
[rename.block_id].into_iter().collect(),
|
||||
Some(Autoscroll::fit()),
|
||||
@@ -9172,17 +9169,13 @@ impl Editor {
|
||||
self.focus_handle.is_focused(cx)
|
||||
}
|
||||
|
||||
fn handle_focus_in(&mut self, cx: &mut ViewContext<Self>) {
|
||||
if self.focus_handle.is_focused(cx) {
|
||||
// todo!()
|
||||
// let focused_event = EditorFocused(cx.handle());
|
||||
// cx.emit_global(focused_event);
|
||||
cx.emit(EditorEvent::Focused);
|
||||
}
|
||||
fn handle_focus(&mut self, cx: &mut ViewContext<Self>) {
|
||||
cx.emit(EditorEvent::Focused);
|
||||
|
||||
if let Some(rename) = self.pending_rename.as_ref() {
|
||||
let rename_editor_focus_handle = rename.editor.read(cx).focus_handle.clone();
|
||||
cx.focus(&rename_editor_focus_handle);
|
||||
} else if self.focus_handle.is_focused(cx) {
|
||||
} else {
|
||||
self.blink_manager.update(cx, BlinkManager::enable);
|
||||
self.buffer.update(cx, |buffer, cx| {
|
||||
buffer.finalize_last_transaction(cx);
|
||||
@@ -9198,7 +9191,7 @@ impl Editor {
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_focus_out(&mut self, cx: &mut ViewContext<Self>) {
|
||||
fn handle_blur(&mut self, cx: &mut ViewContext<Self>) {
|
||||
// todo!()
|
||||
// let blurred_event = EditorBlurred(cx.handle());
|
||||
// cx.emit_global(blurred_event);
|
||||
|
||||
@@ -3851,12 +3851,12 @@ async fn test_select_larger_smaller_syntax_node(cx: &mut gpui::TestAppContext) {
|
||||
Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx)
|
||||
});
|
||||
let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx));
|
||||
let (view, mut cx) = cx.add_window_view(|cx| build_editor(buffer, cx));
|
||||
let (view, cx) = cx.add_window_view(|cx| build_editor(buffer, cx));
|
||||
|
||||
view.condition::<crate::EditorEvent>(&cx, |view, cx| !view.buffer.read(cx).is_parsing(cx))
|
||||
.await;
|
||||
|
||||
view.update(&mut cx, |view, cx| {
|
||||
view.update(cx, |view, cx| {
|
||||
view.change_selections(None, cx, |s| {
|
||||
s.select_display_ranges([
|
||||
DisplayPoint::new(0, 25)..DisplayPoint::new(0, 25),
|
||||
@@ -3867,7 +3867,7 @@ async fn test_select_larger_smaller_syntax_node(cx: &mut gpui::TestAppContext) {
|
||||
view.select_larger_syntax_node(&SelectLargerSyntaxNode, cx);
|
||||
});
|
||||
assert_eq!(
|
||||
view.update(&mut cx, |view, cx| { view.selections.display_ranges(cx) }),
|
||||
view.update(cx, |view, cx| { view.selections.display_ranges(cx) }),
|
||||
&[
|
||||
DisplayPoint::new(0, 23)..DisplayPoint::new(0, 27),
|
||||
DisplayPoint::new(2, 35)..DisplayPoint::new(2, 7),
|
||||
@@ -3875,50 +3875,50 @@ async fn test_select_larger_smaller_syntax_node(cx: &mut gpui::TestAppContext) {
|
||||
]
|
||||
);
|
||||
|
||||
view.update(&mut cx, |view, cx| {
|
||||
view.update(cx, |view, cx| {
|
||||
view.select_larger_syntax_node(&SelectLargerSyntaxNode, cx);
|
||||
});
|
||||
assert_eq!(
|
||||
view.update(&mut cx, |view, cx| view.selections.display_ranges(cx)),
|
||||
view.update(cx, |view, cx| view.selections.display_ranges(cx)),
|
||||
&[
|
||||
DisplayPoint::new(0, 16)..DisplayPoint::new(0, 28),
|
||||
DisplayPoint::new(4, 1)..DisplayPoint::new(2, 0),
|
||||
]
|
||||
);
|
||||
|
||||
view.update(&mut cx, |view, cx| {
|
||||
view.update(cx, |view, cx| {
|
||||
view.select_larger_syntax_node(&SelectLargerSyntaxNode, cx);
|
||||
});
|
||||
assert_eq!(
|
||||
view.update(&mut cx, |view, cx| view.selections.display_ranges(cx)),
|
||||
view.update(cx, |view, cx| view.selections.display_ranges(cx)),
|
||||
&[DisplayPoint::new(5, 0)..DisplayPoint::new(0, 0)]
|
||||
);
|
||||
|
||||
// Trying to expand the selected syntax node one more time has no effect.
|
||||
view.update(&mut cx, |view, cx| {
|
||||
view.update(cx, |view, cx| {
|
||||
view.select_larger_syntax_node(&SelectLargerSyntaxNode, cx);
|
||||
});
|
||||
assert_eq!(
|
||||
view.update(&mut cx, |view, cx| view.selections.display_ranges(cx)),
|
||||
view.update(cx, |view, cx| view.selections.display_ranges(cx)),
|
||||
&[DisplayPoint::new(5, 0)..DisplayPoint::new(0, 0)]
|
||||
);
|
||||
|
||||
view.update(&mut cx, |view, cx| {
|
||||
view.update(cx, |view, cx| {
|
||||
view.select_smaller_syntax_node(&SelectSmallerSyntaxNode, cx);
|
||||
});
|
||||
assert_eq!(
|
||||
view.update(&mut cx, |view, cx| view.selections.display_ranges(cx)),
|
||||
view.update(cx, |view, cx| view.selections.display_ranges(cx)),
|
||||
&[
|
||||
DisplayPoint::new(0, 16)..DisplayPoint::new(0, 28),
|
||||
DisplayPoint::new(4, 1)..DisplayPoint::new(2, 0),
|
||||
]
|
||||
);
|
||||
|
||||
view.update(&mut cx, |view, cx| {
|
||||
view.update(cx, |view, cx| {
|
||||
view.select_smaller_syntax_node(&SelectSmallerSyntaxNode, cx);
|
||||
});
|
||||
assert_eq!(
|
||||
view.update(&mut cx, |view, cx| view.selections.display_ranges(cx)),
|
||||
view.update(cx, |view, cx| view.selections.display_ranges(cx)),
|
||||
&[
|
||||
DisplayPoint::new(0, 23)..DisplayPoint::new(0, 27),
|
||||
DisplayPoint::new(2, 35)..DisplayPoint::new(2, 7),
|
||||
@@ -3926,11 +3926,11 @@ async fn test_select_larger_smaller_syntax_node(cx: &mut gpui::TestAppContext) {
|
||||
]
|
||||
);
|
||||
|
||||
view.update(&mut cx, |view, cx| {
|
||||
view.update(cx, |view, cx| {
|
||||
view.select_smaller_syntax_node(&SelectSmallerSyntaxNode, cx);
|
||||
});
|
||||
assert_eq!(
|
||||
view.update(&mut cx, |view, cx| view.selections.display_ranges(cx)),
|
||||
view.update(cx, |view, cx| view.selections.display_ranges(cx)),
|
||||
&[
|
||||
DisplayPoint::new(0, 25)..DisplayPoint::new(0, 25),
|
||||
DisplayPoint::new(2, 24)..DisplayPoint::new(2, 12),
|
||||
@@ -3939,11 +3939,11 @@ async fn test_select_larger_smaller_syntax_node(cx: &mut gpui::TestAppContext) {
|
||||
);
|
||||
|
||||
// Trying to shrink the selected syntax node one more time has no effect.
|
||||
view.update(&mut cx, |view, cx| {
|
||||
view.update(cx, |view, cx| {
|
||||
view.select_smaller_syntax_node(&SelectSmallerSyntaxNode, cx);
|
||||
});
|
||||
assert_eq!(
|
||||
view.update(&mut cx, |view, cx| view.selections.display_ranges(cx)),
|
||||
view.update(cx, |view, cx| view.selections.display_ranges(cx)),
|
||||
&[
|
||||
DisplayPoint::new(0, 25)..DisplayPoint::new(0, 25),
|
||||
DisplayPoint::new(2, 24)..DisplayPoint::new(2, 12),
|
||||
@@ -3953,7 +3953,7 @@ async fn test_select_larger_smaller_syntax_node(cx: &mut gpui::TestAppContext) {
|
||||
|
||||
// Ensure that we keep expanding the selection if the larger selection starts or ends within
|
||||
// a fold.
|
||||
view.update(&mut cx, |view, cx| {
|
||||
view.update(cx, |view, cx| {
|
||||
view.fold_ranges(
|
||||
vec![
|
||||
Point::new(0, 21)..Point::new(0, 24),
|
||||
@@ -3965,7 +3965,7 @@ async fn test_select_larger_smaller_syntax_node(cx: &mut gpui::TestAppContext) {
|
||||
view.select_larger_syntax_node(&SelectLargerSyntaxNode, cx);
|
||||
});
|
||||
assert_eq!(
|
||||
view.update(&mut cx, |view, cx| view.selections.display_ranges(cx)),
|
||||
view.update(cx, |view, cx| view.selections.display_ranges(cx)),
|
||||
&[
|
||||
DisplayPoint::new(0, 16)..DisplayPoint::new(0, 28),
|
||||
DisplayPoint::new(2, 35)..DisplayPoint::new(2, 7),
|
||||
@@ -4017,8 +4017,7 @@ async fn test_autoindent_selections(cx: &mut gpui::TestAppContext) {
|
||||
Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx)
|
||||
});
|
||||
let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx));
|
||||
let (editor, mut cx) = cx.add_window_view(|cx| build_editor(buffer, cx));
|
||||
let cx = &mut cx;
|
||||
let (editor, cx) = cx.add_window_view(|cx| build_editor(buffer, cx));
|
||||
editor
|
||||
.condition::<crate::EditorEvent>(cx, |editor, cx| !editor.buffer.read(cx).is_parsing(cx))
|
||||
.await;
|
||||
@@ -4583,8 +4582,7 @@ async fn test_surround_with_pair(cx: &mut gpui::TestAppContext) {
|
||||
Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx)
|
||||
});
|
||||
let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx));
|
||||
let (view, mut cx) = cx.add_window_view(|cx| build_editor(buffer, cx));
|
||||
let cx = &mut cx;
|
||||
let (view, cx) = cx.add_window_view(|cx| build_editor(buffer, cx));
|
||||
view.condition::<crate::EditorEvent>(cx, |view, cx| !view.buffer.read(cx).is_parsing(cx))
|
||||
.await;
|
||||
|
||||
@@ -4734,8 +4732,7 @@ async fn test_delete_autoclose_pair(cx: &mut gpui::TestAppContext) {
|
||||
Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx)
|
||||
});
|
||||
let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx));
|
||||
let (editor, mut cx) = cx.add_window_view(|cx| build_editor(buffer, cx));
|
||||
let cx = &mut cx;
|
||||
let (editor, cx) = cx.add_window_view(|cx| build_editor(buffer, cx));
|
||||
editor
|
||||
.condition::<crate::EditorEvent>(cx, |view, cx| !view.buffer.read(cx).is_parsing(cx))
|
||||
.await;
|
||||
@@ -4957,8 +4954,7 @@ async fn test_document_format_during_save(cx: &mut gpui::TestAppContext) {
|
||||
let fake_server = fake_servers.next().await.unwrap();
|
||||
|
||||
let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx));
|
||||
let (editor, mut cx) = cx.add_window_view(|cx| build_editor(buffer, cx));
|
||||
let cx = &mut cx;
|
||||
let (editor, cx) = cx.add_window_view(|cx| build_editor(buffer, cx));
|
||||
editor.update(cx, |editor, cx| editor.set_text("one\ntwo\nthree\n", cx));
|
||||
assert!(cx.read(|cx| editor.is_dirty(cx)));
|
||||
|
||||
@@ -5077,8 +5073,7 @@ async fn test_range_format_during_save(cx: &mut gpui::TestAppContext) {
|
||||
let fake_server = fake_servers.next().await.unwrap();
|
||||
|
||||
let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx));
|
||||
let (editor, mut cx) = cx.add_window_view(|cx| build_editor(buffer, cx));
|
||||
let cx = &mut cx;
|
||||
let (editor, cx) = cx.add_window_view(|cx| build_editor(buffer, cx));
|
||||
editor.update(cx, |editor, cx| editor.set_text("one\ntwo\nthree\n", cx));
|
||||
assert!(cx.read(|cx| editor.is_dirty(cx)));
|
||||
|
||||
@@ -5205,8 +5200,7 @@ async fn test_document_format_manual_trigger(cx: &mut gpui::TestAppContext) {
|
||||
let fake_server = fake_servers.next().await.unwrap();
|
||||
|
||||
let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx));
|
||||
let (editor, mut cx) = cx.add_window_view(|cx| build_editor(buffer, cx));
|
||||
let cx = &mut cx;
|
||||
let (editor, cx) = cx.add_window_view(|cx| build_editor(buffer, cx));
|
||||
editor.update(cx, |editor, cx| editor.set_text("one\ntwo\nthree\n", cx));
|
||||
|
||||
let format = editor
|
||||
@@ -5993,8 +5987,7 @@ fn test_editing_disjoint_excerpts(cx: &mut TestAppContext) {
|
||||
multibuffer
|
||||
});
|
||||
|
||||
let (view, mut cx) = cx.add_window_view(|cx| build_editor(multibuffer, cx));
|
||||
let cx = &mut cx;
|
||||
let (view, cx) = cx.add_window_view(|cx| build_editor(multibuffer, cx));
|
||||
view.update(cx, |view, cx| {
|
||||
assert_eq!(view.text(cx), "aaaa\nbbbb");
|
||||
view.change_selections(None, cx, |s| {
|
||||
@@ -6064,8 +6057,7 @@ fn test_editing_overlapping_excerpts(cx: &mut TestAppContext) {
|
||||
multibuffer
|
||||
});
|
||||
|
||||
let (view, mut cx) = cx.add_window_view(|cx| build_editor(multibuffer, cx));
|
||||
let cx = &mut cx;
|
||||
let (view, cx) = cx.add_window_view(|cx| build_editor(multibuffer, cx));
|
||||
view.update(cx, |view, cx| {
|
||||
let (expected_text, selection_ranges) = marked_text_ranges(
|
||||
indoc! {"
|
||||
@@ -6302,8 +6294,7 @@ async fn test_extra_newline_insertion(cx: &mut gpui::TestAppContext) {
|
||||
Buffer::new(0, cx.entity_id().as_u64(), text).with_language(language, cx)
|
||||
});
|
||||
let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx));
|
||||
let (view, mut cx) = cx.add_window_view(|cx| build_editor(buffer, cx));
|
||||
let cx = &mut cx;
|
||||
let (view, cx) = cx.add_window_view(|cx| build_editor(buffer, cx));
|
||||
view.condition::<crate::EditorEvent>(cx, |view, cx| !view.buffer.read(cx).is_parsing(cx))
|
||||
.await;
|
||||
|
||||
@@ -8112,8 +8103,7 @@ async fn test_document_format_with_prettier(cx: &mut gpui::TestAppContext) {
|
||||
|
||||
let buffer_text = "one\ntwo\nthree\n";
|
||||
let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx));
|
||||
let (editor, mut cx) = cx.add_window_view(|cx| build_editor(buffer, cx));
|
||||
let cx = &mut cx;
|
||||
let (editor, cx) = cx.add_window_view(|cx| build_editor(buffer, cx));
|
||||
editor.update(cx, |editor, cx| editor.set_text(buffer_text, cx));
|
||||
|
||||
editor
|
||||
|
||||
+568
-617
File diff suppressed because it is too large
Load Diff
@@ -60,8 +60,8 @@ pub fn diff_hunk_to_display(hunk: DiffHunk<u32>, snapshot: &DisplaySnapshot) ->
|
||||
let folds_end = Point::new(hunk.buffer_range.end + 2, 0);
|
||||
let folds_range = folds_start..folds_end;
|
||||
|
||||
let containing_fold = snapshot.folds_in_range(folds_range).find(|fold_range| {
|
||||
let fold_point_range = fold_range.to_point(&snapshot.buffer_snapshot);
|
||||
let containing_fold = snapshot.folds_in_range(folds_range).find(|fold| {
|
||||
let fold_point_range = fold.range.to_point(&snapshot.buffer_snapshot);
|
||||
let fold_point_range = fold_point_range.start..=fold_point_range.end;
|
||||
|
||||
let folded_start = fold_point_range.contains(&hunk_start_point);
|
||||
@@ -72,7 +72,7 @@ pub fn diff_hunk_to_display(hunk: DiffHunk<u32>, snapshot: &DisplaySnapshot) ->
|
||||
});
|
||||
|
||||
if let Some(fold) = containing_fold {
|
||||
let row = fold.start.to_display_point(snapshot).row();
|
||||
let row = fold.range.start.to_display_point(snapshot).row();
|
||||
DisplayDiffHunk::Folded { display_row: row }
|
||||
} else {
|
||||
let start = hunk_start_point.to_display_point(snapshot).row();
|
||||
|
||||
Reference in New Issue
Block a user