Compare commits
1 Commits
commit-vie
...
multi-buff
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
358ca91621 |
@@ -33,7 +33,7 @@ use editor::{
|
|||||||
},
|
},
|
||||||
scroll::{Autoscroll, AutoscrollStrategy},
|
scroll::{Autoscroll, AutoscrollStrategy},
|
||||||
Anchor, Editor, EditorEvent, ProposedChangeLocation, ProposedChangesEditor, RowExt,
|
Anchor, Editor, EditorEvent, ProposedChangeLocation, ProposedChangesEditor, RowExt,
|
||||||
ToOffset as _, ToPoint,
|
ToMultiBufferPoint, ToOffset as _,
|
||||||
};
|
};
|
||||||
use editor::{display_map::CreaseId, FoldPlaceholder};
|
use editor::{display_map::CreaseId, FoldPlaceholder};
|
||||||
use fs::Fs;
|
use fs::Fs;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use editor::{
|
|||||||
},
|
},
|
||||||
Anchor, AnchorRangeExt, CodeActionProvider, Editor, EditorElement, EditorEvent, EditorMode,
|
Anchor, AnchorRangeExt, CodeActionProvider, Editor, EditorElement, EditorEvent, EditorMode,
|
||||||
EditorStyle, ExcerptId, ExcerptRange, GutterDimensions, MultiBuffer, MultiBufferSnapshot,
|
EditorStyle, ExcerptId, ExcerptRange, GutterDimensions, MultiBuffer, MultiBufferSnapshot,
|
||||||
ToOffset as _, ToPoint,
|
ToMultiBufferPoint, ToOffset as _,
|
||||||
};
|
};
|
||||||
use feature_flags::{FeatureFlagAppExt as _, ZedPro};
|
use feature_flags::{FeatureFlagAppExt as _, ZedPro};
|
||||||
use fs::Fs;
|
use fs::Fs;
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ use language::{
|
|||||||
use lsp::DiagnosticSeverity;
|
use lsp::DiagnosticSeverity;
|
||||||
use multi_buffer::{
|
use multi_buffer::{
|
||||||
Anchor, AnchorRangeExt, MultiBuffer, MultiBufferPoint, MultiBufferRow, MultiBufferSnapshot,
|
Anchor, AnchorRangeExt, MultiBuffer, MultiBufferPoint, MultiBufferRow, MultiBufferSnapshot,
|
||||||
ToOffset, ToPoint,
|
ToMultiBufferPoint, ToOffset,
|
||||||
};
|
};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::{
|
use std::{
|
||||||
@@ -688,7 +688,10 @@ impl DisplaySnapshot {
|
|||||||
self.buffer_snapshot.max_buffer_row()
|
self.buffer_snapshot.max_buffer_row()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prev_line_boundary(&self, mut point: MultiBufferPoint) -> (Point, DisplayPoint) {
|
pub fn prev_line_boundary(
|
||||||
|
&self,
|
||||||
|
mut point: MultiBufferPoint,
|
||||||
|
) -> (MultiBufferPoint, DisplayPoint) {
|
||||||
loop {
|
loop {
|
||||||
let mut inlay_point = self.inlay_snapshot.to_inlay_point(point);
|
let mut inlay_point = self.inlay_snapshot.to_inlay_point(point);
|
||||||
let mut fold_point = self.fold_snapshot.to_fold_point(inlay_point, Bias::Left);
|
let mut fold_point = self.fold_snapshot.to_fold_point(inlay_point, Bias::Left);
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ use collections::{Bound, HashMap, HashSet};
|
|||||||
use gpui::{AnyElement, EntityId, Pixels, WindowContext};
|
use gpui::{AnyElement, EntityId, Pixels, WindowContext};
|
||||||
use language::{Chunk, Patch, Point};
|
use language::{Chunk, Patch, Point};
|
||||||
use multi_buffer::{
|
use multi_buffer::{
|
||||||
Anchor, ExcerptId, ExcerptInfo, MultiBufferRow, MultiBufferSnapshot, ToOffset, ToPoint as _,
|
Anchor, ExcerptId, ExcerptInfo, MultiBufferPoint, MultiBufferRow, MultiBufferSnapshot,
|
||||||
|
ToMultiBufferPoint as _, ToOffset,
|
||||||
};
|
};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use std::{
|
use std::{
|
||||||
@@ -738,13 +739,13 @@ impl BlockMap {
|
|||||||
let wrap_row;
|
let wrap_row;
|
||||||
if excerpt_boundary.next.is_some() {
|
if excerpt_boundary.next.is_some() {
|
||||||
wrap_row = wrap_snapshot
|
wrap_row = wrap_snapshot
|
||||||
.make_wrap_point(Point::new(excerpt_boundary.row.0, 0), Bias::Left)
|
.make_wrap_point(MultiBufferPoint::new(excerpt_boundary.row, 0), Bias::Left)
|
||||||
.row();
|
.row();
|
||||||
} else {
|
} else {
|
||||||
wrap_row = wrap_snapshot
|
wrap_row = wrap_snapshot
|
||||||
.make_wrap_point(
|
.make_wrap_point(
|
||||||
Point::new(
|
MultiBufferPoint::new(
|
||||||
excerpt_boundary.row.0,
|
excerpt_boundary.row,
|
||||||
buffer.line_len(excerpt_boundary.row),
|
buffer.line_len(excerpt_boundary.row),
|
||||||
),
|
),
|
||||||
Bias::Left,
|
Bias::Left,
|
||||||
@@ -1366,7 +1367,7 @@ impl BlockSnapshot {
|
|||||||
pub(super) fn is_line_replaced(&self, row: MultiBufferRow) -> bool {
|
pub(super) fn is_line_replaced(&self, row: MultiBufferRow) -> bool {
|
||||||
let wrap_point = self
|
let wrap_point = self
|
||||||
.wrap_snapshot
|
.wrap_snapshot
|
||||||
.make_wrap_point(Point::new(row.0, 0), Bias::Left);
|
.make_wrap_point(MultiBufferPoint::new(row, 0), Bias::Left);
|
||||||
let mut cursor = self.transforms.cursor::<(WrapRow, BlockRow)>(&());
|
let mut cursor = self.transforms.cursor::<(WrapRow, BlockRow)>(&());
|
||||||
cursor.seek(&WrapRow(wrap_point.row()), Bias::Right, &());
|
cursor.seek(&WrapRow(wrap_point.row()), Bias::Right, &());
|
||||||
cursor.item().map_or(false, |transform| {
|
cursor.item().map_or(false, |transform| {
|
||||||
@@ -2511,7 +2512,7 @@ mod tests {
|
|||||||
let wrap_row = wrap_row as u32;
|
let wrap_row = wrap_row as u32;
|
||||||
let multibuffer_row = wraps_snapshot
|
let multibuffer_row = wraps_snapshot
|
||||||
.to_point(WrapPoint::new(wrap_row, 0), Bias::Left)
|
.to_point(WrapPoint::new(wrap_row, 0), Bias::Left)
|
||||||
.row;
|
.row();
|
||||||
|
|
||||||
// Create empty lines for the above block
|
// Create empty lines for the above block
|
||||||
while let Some((placement, block)) = sorted_blocks_iter.peek() {
|
while let Some((placement, block)) = sorted_blocks_iter.peek() {
|
||||||
@@ -2543,7 +2544,8 @@ mod tests {
|
|||||||
is_in_replace_block = true;
|
is_in_replace_block = true;
|
||||||
|
|
||||||
if wrap_row == replace_range.start.0 {
|
if wrap_row == replace_range.start.0 {
|
||||||
expected_buffer_rows.push(input_buffer_rows[multibuffer_row as usize]);
|
expected_buffer_rows
|
||||||
|
.push(input_buffer_rows[multibuffer_row.0 as usize]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if wrap_row == replace_range.end.0 {
|
if wrap_row == replace_range.end.0 {
|
||||||
@@ -2565,9 +2567,9 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if is_in_replace_block {
|
if is_in_replace_block {
|
||||||
expected_replaced_buffer_rows.insert(MultiBufferRow(multibuffer_row));
|
expected_replaced_buffer_rows.insert(multibuffer_row);
|
||||||
} else {
|
} else {
|
||||||
let buffer_row = input_buffer_rows[multibuffer_row as usize];
|
let buffer_row = input_buffer_rows[multibuffer_row.0 as usize];
|
||||||
let soft_wrapped = wraps_snapshot
|
let soft_wrapped = wraps_snapshot
|
||||||
.to_tab_point(WrapPoint::new(wrap_row, 0))
|
.to_tab_point(WrapPoint::new(wrap_row, 0))
|
||||||
.column()
|
.column()
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
use gpui::{AnyElement, IntoElement};
|
use gpui::{AnyElement, IntoElement};
|
||||||
use multi_buffer::{Anchor, AnchorRangeExt, MultiBufferRow, MultiBufferSnapshot, ToPoint};
|
use multi_buffer::{
|
||||||
|
Anchor, AnchorRangeExt, MultiBufferRow, MultiBufferSnapshot, ToMultiBufferPoint,
|
||||||
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{cmp::Ordering, fmt::Debug, ops::Range, sync::Arc};
|
use std::{cmp::Ordering, fmt::Debug, ops::Range, sync::Arc};
|
||||||
use sum_tree::{Bias, SeekTarget, SumTree};
|
use sum_tree::{Bias, SeekTarget, SumTree};
|
||||||
|
|||||||
@@ -1380,7 +1380,7 @@ pub type FoldEdit = Edit<FoldOffset>;
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{display_map::inlay_map::InlayMap, MultiBuffer, ToPoint};
|
use crate::{display_map::inlay_map::InlayMap, MultiBuffer, ToMultiBufferPoint};
|
||||||
use collections::HashSet;
|
use collections::HashSet;
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
use settings::SettingsStore;
|
use settings::SettingsStore;
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ use collections::{BTreeMap, BTreeSet};
|
|||||||
use gpui::HighlightStyle;
|
use gpui::HighlightStyle;
|
||||||
use language::{Chunk, Edit, Point, TextSummary};
|
use language::{Chunk, Edit, Point, TextSummary};
|
||||||
use multi_buffer::{
|
use multi_buffer::{
|
||||||
Anchor, MultiBufferChunks, MultiBufferRow, MultiBufferRows, MultiBufferSnapshot, ToOffset,
|
Anchor, MultiBufferChunks, MultiBufferPoint, MultiBufferRow, MultiBufferRows,
|
||||||
|
MultiBufferSnapshot, ToOffset,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
any::TypeId,
|
any::TypeId,
|
||||||
@@ -777,7 +778,7 @@ impl InlaySnapshot {
|
|||||||
None => self.len(),
|
None => self.len(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn to_buffer_point(&self, point: InlayPoint) -> Point {
|
pub fn to_buffer_point(&self, point: InlayPoint) -> MultiBufferPoint {
|
||||||
let mut cursor = self.transforms.cursor::<(InlayPoint, Point)>(&());
|
let mut cursor = self.transforms.cursor::<(InlayPoint, Point)>(&());
|
||||||
cursor.seek(&point, Bias::Right, &());
|
cursor.seek(&point, Bias::Right, &());
|
||||||
match cursor.item() {
|
match cursor.item() {
|
||||||
@@ -835,7 +836,7 @@ impl InlaySnapshot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn to_inlay_point(&self, point: Point) -> InlayPoint {
|
pub fn to_inlay_point(&self, point: MultiBufferPoint) -> InlayPoint {
|
||||||
let mut cursor = self.transforms.cursor::<(Point, InlayPoint)>(&());
|
let mut cursor = self.transforms.cursor::<(Point, InlayPoint)>(&());
|
||||||
cursor.seek(&point, Bias::Left, &());
|
cursor.seek(&point, Bias::Left, &());
|
||||||
loop {
|
loop {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use super::{
|
|||||||
Highlights,
|
Highlights,
|
||||||
};
|
};
|
||||||
use language::{Chunk, Point};
|
use language::{Chunk, Point};
|
||||||
use multi_buffer::MultiBufferSnapshot;
|
use multi_buffer::{MultiBufferPoint, MultiBufferSnapshot};
|
||||||
use std::{cmp, mem, num::NonZeroU32, ops::Range};
|
use std::{cmp, mem, num::NonZeroU32, ops::Range};
|
||||||
use sum_tree::Bias;
|
use sum_tree::Bias;
|
||||||
|
|
||||||
@@ -316,13 +316,13 @@ impl TabSnapshot {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn make_tab_point(&self, point: Point, bias: Bias) -> TabPoint {
|
pub fn make_tab_point(&self, point: MultiBufferPoint, bias: Bias) -> TabPoint {
|
||||||
let inlay_point = self.fold_snapshot.inlay_snapshot.to_inlay_point(point);
|
let inlay_point = self.fold_snapshot.inlay_snapshot.to_inlay_point(point);
|
||||||
let fold_point = self.fold_snapshot.to_fold_point(inlay_point, bias);
|
let fold_point = self.fold_snapshot.to_fold_point(inlay_point, bias);
|
||||||
self.to_tab_point(fold_point)
|
self.to_tab_point(fold_point)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_point(&self, point: TabPoint, bias: Bias) -> Point {
|
pub fn to_point(&self, point: TabPoint, bias: Bias) -> MultiBufferPoint {
|
||||||
let fold_point = self.to_fold_point(point, bias).0;
|
let fold_point = self.to_fold_point(point, bias).0;
|
||||||
let inlay_point = fold_point.to_inlay_point(&self.fold_snapshot);
|
let inlay_point = fold_point.to_inlay_point(&self.fold_snapshot);
|
||||||
self.fold_snapshot
|
self.fold_snapshot
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use super::{
|
|||||||
};
|
};
|
||||||
use gpui::{AppContext, Context, Font, LineWrapper, Model, ModelContext, Pixels, Task};
|
use gpui::{AppContext, Context, Font, LineWrapper, Model, ModelContext, Pixels, Task};
|
||||||
use language::{Chunk, Point};
|
use language::{Chunk, Point};
|
||||||
use multi_buffer::MultiBufferSnapshot;
|
use multi_buffer::{MultiBufferPoint, MultiBufferSnapshot};
|
||||||
use smol::future::yield_now;
|
use smol::future::yield_now;
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
use std::{cmp, collections::VecDeque, mem, ops::Range, time::Duration};
|
use std::{cmp, collections::VecDeque, mem, ops::Range, time::Duration};
|
||||||
@@ -747,11 +747,11 @@ impl WrapSnapshot {
|
|||||||
TabPoint(tab_point)
|
TabPoint(tab_point)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_point(&self, point: WrapPoint, bias: Bias) -> Point {
|
pub fn to_point(&self, point: WrapPoint, bias: Bias) -> MultiBufferPoint {
|
||||||
self.tab_snapshot.to_point(self.to_tab_point(point), bias)
|
self.tab_snapshot.to_point(self.to_tab_point(point), bias)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn make_wrap_point(&self, point: Point, bias: Bias) -> WrapPoint {
|
pub fn make_wrap_point(&self, point: MultiBufferPoint, bias: Bias) -> WrapPoint {
|
||||||
self.tab_point_to_wrap_point(self.tab_snapshot.make_tab_point(point, bias))
|
self.tab_point_to_wrap_point(self.tab_snapshot.make_tab_point(point, bias))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -114,8 +114,8 @@ use lsp::{
|
|||||||
use mouse_context_menu::MouseContextMenu;
|
use mouse_context_menu::MouseContextMenu;
|
||||||
use movement::TextLayoutDetails;
|
use movement::TextLayoutDetails;
|
||||||
pub use multi_buffer::{
|
pub use multi_buffer::{
|
||||||
Anchor, AnchorRangeExt, ExcerptId, ExcerptRange, MultiBuffer, MultiBufferSnapshot, ToOffset,
|
Anchor, AnchorRangeExt, ExcerptId, ExcerptRange, MultiBuffer, MultiBufferSnapshot,
|
||||||
ToPoint,
|
ToMultiBufferPoint, ToOffset,
|
||||||
};
|
};
|
||||||
use multi_buffer::{
|
use multi_buffer::{
|
||||||
ExpandExcerptDirection, MultiBufferDiffHunk, MultiBufferPoint, MultiBufferRow, ToOffsetUtf16,
|
ExpandExcerptDirection, MultiBufferDiffHunk, MultiBufferPoint, MultiBufferRow, ToOffsetUtf16,
|
||||||
@@ -14703,7 +14703,7 @@ trait SelectionExt {
|
|||||||
) -> Range<MultiBufferRow>;
|
) -> Range<MultiBufferRow>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ToPoint + ToOffset> SelectionExt for Selection<T> {
|
impl<T: ToMultiBufferPoint + ToOffset> SelectionExt for Selection<T> {
|
||||||
fn display_range(&self, map: &DisplaySnapshot) -> Range<DisplayPoint> {
|
fn display_range(&self, map: &DisplaySnapshot) -> Range<DisplayPoint> {
|
||||||
let start = self
|
let start = self
|
||||||
.start
|
.start
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ use crate::{
|
|||||||
DisplayRow, DocumentHighlightRead, DocumentHighlightWrite, Editor, EditorMode, EditorSettings,
|
DisplayRow, DocumentHighlightRead, DocumentHighlightWrite, Editor, EditorMode, EditorSettings,
|
||||||
EditorSnapshot, EditorStyle, ExpandExcerpts, FocusedBlock, GutterDimensions, HalfPageDown,
|
EditorSnapshot, EditorStyle, ExpandExcerpts, FocusedBlock, GutterDimensions, HalfPageDown,
|
||||||
HalfPageUp, HandleInput, HoveredCursor, HoveredHunk, JumpData, LineDown, LineUp, OpenExcerpts,
|
HalfPageUp, HandleInput, HoveredCursor, HoveredHunk, JumpData, LineDown, LineUp, OpenExcerpts,
|
||||||
PageDown, PageUp, Point, RowExt, RowRangeExt, SelectPhase, Selection, SoftWrap, ToPoint,
|
PageDown, PageUp, Point, RowExt, RowRangeExt, SelectPhase, Selection, SoftWrap,
|
||||||
CURSORS_VISIBLE_FOR, FILE_HEADER_HEIGHT, GIT_BLAME_MAX_AUTHOR_CHARS_DISPLAYED, MAX_LINE_LEN,
|
ToMultiBufferPoint, CURSORS_VISIBLE_FOR, FILE_HEADER_HEIGHT,
|
||||||
MULTI_BUFFER_EXCERPT_HEADER_HEIGHT,
|
GIT_BLAME_MAX_AUTHOR_CHARS_DISPLAYED, MAX_LINE_LEN, MULTI_BUFFER_EXCERPT_HEADER_HEIGHT,
|
||||||
};
|
};
|
||||||
use client::ParticipantIndex;
|
use client::ParticipantIndex;
|
||||||
use collections::{BTreeMap, HashMap, HashSet};
|
use collections::{BTreeMap, HashMap, HashSet};
|
||||||
@@ -84,7 +84,7 @@ struct SelectionLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl SelectionLayout {
|
impl SelectionLayout {
|
||||||
fn new<T: ToPoint + ToDisplayPoint + Clone>(
|
fn new<T: ToMultiBufferPoint + ToDisplayPoint + Clone>(
|
||||||
selection: Selection<T>,
|
selection: Selection<T>,
|
||||||
line_mode: bool,
|
line_mode: bool,
|
||||||
cursor_shape: CursorShape,
|
cursor_shape: CursorShape,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use gpui::{Action, AnchorCorner, AppContext, CursorStyle, Hsla, Model, MouseButt
|
|||||||
use language::{Buffer, BufferId, Point};
|
use language::{Buffer, BufferId, Point};
|
||||||
use multi_buffer::{
|
use multi_buffer::{
|
||||||
Anchor, AnchorRangeExt, ExcerptRange, MultiBuffer, MultiBufferDiffHunk, MultiBufferRow,
|
Anchor, AnchorRangeExt, ExcerptRange, MultiBuffer, MultiBufferDiffHunk, MultiBufferRow,
|
||||||
MultiBufferSnapshot, ToPoint,
|
MultiBufferSnapshot, ToMultiBufferPoint,
|
||||||
};
|
};
|
||||||
use std::{ops::Range, sync::Arc};
|
use std::{ops::Range, sync::Arc};
|
||||||
use text::OffsetRangeExt;
|
use text::OffsetRangeExt;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use crate::{
|
|||||||
persistence::{SerializedEditor, DB},
|
persistence::{SerializedEditor, DB},
|
||||||
scroll::ScrollAnchor,
|
scroll::ScrollAnchor,
|
||||||
Anchor, Autoscroll, Editor, EditorEvent, EditorSettings, ExcerptId, ExcerptRange, MultiBuffer,
|
Anchor, Autoscroll, Editor, EditorEvent, EditorSettings, ExcerptId, ExcerptRange, MultiBuffer,
|
||||||
MultiBufferSnapshot, NavigationData, SearchWithinRange, ToPoint as _,
|
MultiBufferSnapshot, NavigationData, SearchWithinRange, ToMultiBufferPoint as _,
|
||||||
};
|
};
|
||||||
use anyhow::{anyhow, Context as _, Result};
|
use anyhow::{anyhow, Context as _, Result};
|
||||||
use collections::HashSet;
|
use collections::HashSet;
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
//! in editor given a given motion (e.g. it handles converting a "move left" command into coordinates in editor). It is exposed mostly for use by vim crate.
|
//! in editor given a given motion (e.g. it handles converting a "move left" command into coordinates in editor). It is exposed mostly for use by vim crate.
|
||||||
|
|
||||||
use super::{Bias, DisplayPoint, DisplaySnapshot, SelectionGoal, ToDisplayPoint};
|
use super::{Bias, DisplayPoint, DisplaySnapshot, SelectionGoal, ToDisplayPoint};
|
||||||
use crate::{scroll::ScrollAnchor, CharKind, DisplayRow, EditorStyle, RowExt, ToOffset, ToPoint};
|
use crate::{
|
||||||
|
scroll::ScrollAnchor, CharKind, DisplayRow, EditorStyle, RowExt, ToMultiBufferPoint, ToOffset,
|
||||||
|
};
|
||||||
use gpui::{Pixels, WindowTextSystem};
|
use gpui::{Pixels, WindowTextSystem};
|
||||||
use language::Point;
|
use language::Point;
|
||||||
use multi_buffer::{MultiBufferRow, MultiBufferSnapshot};
|
use multi_buffer::{MultiBufferRow, MultiBufferSnapshot};
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use crate::{
|
|||||||
hover_popover::hide_hover,
|
hover_popover::hide_hover,
|
||||||
persistence::DB,
|
persistence::DB,
|
||||||
Anchor, DisplayPoint, DisplayRow, Editor, EditorEvent, EditorMode, EditorSettings,
|
Anchor, DisplayPoint, DisplayRow, Editor, EditorEvent, EditorMode, EditorSettings,
|
||||||
InlayHintRefreshReason, MultiBufferSnapshot, RowExt, ToPoint,
|
InlayHintRefreshReason, MultiBufferSnapshot, RowExt, ToMultiBufferPoint,
|
||||||
};
|
};
|
||||||
pub use autoscroll::{Autoscroll, AutoscrollStrategy};
|
pub use autoscroll::{Autoscroll, AutoscrollStrategy};
|
||||||
use gpui::{point, px, AppContext, Entity, Global, Pixels, Task, ViewContext, WindowContext};
|
use gpui::{point, px, AppContext, Entity, Global, Pixels, Task, ViewContext, WindowContext};
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use crate::{
|
|||||||
display_map::{DisplayMap, DisplaySnapshot, ToDisplayPoint},
|
display_map::{DisplayMap, DisplaySnapshot, ToDisplayPoint},
|
||||||
movement::TextLayoutDetails,
|
movement::TextLayoutDetails,
|
||||||
Anchor, DisplayPoint, DisplayRow, ExcerptId, MultiBuffer, MultiBufferSnapshot, SelectMode,
|
Anchor, DisplayPoint, DisplayRow, ExcerptId, MultiBuffer, MultiBufferSnapshot, SelectMode,
|
||||||
ToOffset, ToPoint,
|
ToMultiBufferPoint, ToOffset,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@@ -502,7 +502,13 @@ impl<'a> MutableSelectionsCollection<'a> {
|
|||||||
|
|
||||||
pub fn insert_range<T>(&mut self, range: Range<T>)
|
pub fn insert_range<T>(&mut self, range: Range<T>)
|
||||||
where
|
where
|
||||||
T: 'a + ToOffset + ToPoint + TextDimension + Ord + Sub<T, Output = T> + std::marker::Copy,
|
T: 'a
|
||||||
|
+ ToOffset
|
||||||
|
+ ToMultiBufferPoint
|
||||||
|
+ TextDimension
|
||||||
|
+ Ord
|
||||||
|
+ Sub<T, Output = T>
|
||||||
|
+ std::marker::Copy,
|
||||||
{
|
{
|
||||||
let mut selections = self.collection.all(self.cx);
|
let mut selections = self.collection.all(self.cx);
|
||||||
let mut start = range.start.to_offset(&self.buffer());
|
let mut start = range.start.to_offset(&self.buffer());
|
||||||
@@ -525,7 +531,7 @@ impl<'a> MutableSelectionsCollection<'a> {
|
|||||||
|
|
||||||
pub fn select<T>(&mut self, mut selections: Vec<Selection<T>>)
|
pub fn select<T>(&mut self, mut selections: Vec<Selection<T>>)
|
||||||
where
|
where
|
||||||
T: ToOffset + ToPoint + Ord + std::marker::Copy + std::fmt::Debug,
|
T: ToOffset + ToMultiBufferPoint + Ord + std::marker::Copy + std::fmt::Debug,
|
||||||
{
|
{
|
||||||
let buffer = self.buffer.read(self.cx).snapshot(self.cx);
|
let buffer = self.buffer.read(self.cx).snapshot(self.cx);
|
||||||
selections.sort_unstable_by_key(|s| s.start);
|
selections.sort_unstable_by_key(|s| s.start);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use std::{
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
use crate::{Editor, ToPoint};
|
use crate::{Editor, ToMultiBufferPoint};
|
||||||
use collections::HashSet;
|
use collections::HashSet;
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use gpui::{View, ViewContext, VisualTestContext};
|
use gpui::{View, ViewContext, VisualTestContext};
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use gpui::{
|
|||||||
};
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use language::{Buffer, BufferSnapshot, LanguageRegistry};
|
use language::{Buffer, BufferSnapshot, LanguageRegistry};
|
||||||
use multi_buffer::{ExcerptRange, ToPoint};
|
use multi_buffer::{ExcerptRange, ToMultiBufferPoint};
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use project::{FakeFs, Project};
|
use project::{FakeFs, Project};
|
||||||
use std::{
|
use std::{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use editor::{Editor, ToPoint};
|
use editor::{Editor, ToMultiBufferPoint};
|
||||||
use gpui::{AppContext, FocusHandle, FocusableView, Subscription, Task, View, WeakView};
|
use gpui::{AppContext, FocusHandle, FocusableView, Subscription, Task, View, WeakView};
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
use super::{ExcerptId, MultiBufferSnapshot, ToOffset, ToOffsetUtf16, ToPoint};
|
use crate::MultiBufferPoint;
|
||||||
use language::{OffsetUtf16, Point, TextDimension};
|
|
||||||
|
use super::{ExcerptId, MultiBufferSnapshot, ToMultiBufferPoint, ToOffset, ToOffsetUtf16};
|
||||||
|
use language::{OffsetUtf16, TextDimension};
|
||||||
use std::{
|
use std::{
|
||||||
cmp::Ordering,
|
cmp::Ordering,
|
||||||
ops::{Range, Sub},
|
ops::{Range, Sub},
|
||||||
@@ -109,9 +111,9 @@ impl ToOffsetUtf16 for Anchor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToPoint for Anchor {
|
impl ToMultiBufferPoint for Anchor {
|
||||||
fn to_point<'a>(&self, snapshot: &MultiBufferSnapshot) -> Point {
|
fn to_point<'a>(&self, snapshot: &MultiBufferSnapshot) -> MultiBufferPoint {
|
||||||
self.summary(snapshot)
|
MultiBufferPoint(self.summary(snapshot))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +121,7 @@ pub trait AnchorRangeExt {
|
|||||||
fn cmp(&self, b: &Range<Anchor>, buffer: &MultiBufferSnapshot) -> Ordering;
|
fn cmp(&self, b: &Range<Anchor>, buffer: &MultiBufferSnapshot) -> Ordering;
|
||||||
fn overlaps(&self, b: &Range<Anchor>, buffer: &MultiBufferSnapshot) -> bool;
|
fn overlaps(&self, b: &Range<Anchor>, buffer: &MultiBufferSnapshot) -> bool;
|
||||||
fn to_offset(&self, content: &MultiBufferSnapshot) -> Range<usize>;
|
fn to_offset(&self, content: &MultiBufferSnapshot) -> Range<usize>;
|
||||||
fn to_point(&self, content: &MultiBufferSnapshot) -> Range<Point>;
|
fn to_point(&self, content: &MultiBufferSnapshot) -> Range<MultiBufferPoint>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AnchorRangeExt for Range<Anchor> {
|
impl AnchorRangeExt for Range<Anchor> {
|
||||||
@@ -138,7 +140,7 @@ impl AnchorRangeExt for Range<Anchor> {
|
|||||||
self.start.to_offset(content)..self.end.to_offset(content)
|
self.start.to_offset(content)..self.end.to_offset(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_point(&self, content: &MultiBufferSnapshot) -> Range<Point> {
|
fn to_point(&self, content: &MultiBufferSnapshot) -> Range<MultiBufferPoint> {
|
||||||
self.start.to_point(content)..self.end.to_point(content)
|
self.start.to_point(content)..self.end.to_point(content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ use std::{
|
|||||||
io,
|
io,
|
||||||
iter::{self, FromIterator},
|
iter::{self, FromIterator},
|
||||||
mem,
|
mem,
|
||||||
ops::{Range, RangeBounds, Sub},
|
ops::{Add, AddAssign, Range, RangeBounds, Sub},
|
||||||
str,
|
str,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
@@ -123,12 +123,88 @@ pub struct MultiBufferDiffHunk {
|
|||||||
pub diff_base_byte_range: Range<usize>,
|
pub diff_base_byte_range: Range<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type MultiBufferPoint = Point;
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq, Hash, serde::Deserialize)]
|
#[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq, Hash, serde::Deserialize)]
|
||||||
#[serde(transparent)]
|
#[serde(transparent)]
|
||||||
|
#[repr(transparent)]
|
||||||
pub struct MultiBufferRow(pub u32);
|
pub struct MultiBufferRow(pub u32);
|
||||||
|
|
||||||
|
impl Add<u32> for MultiBufferRow {
|
||||||
|
type Output = MultiBufferRow;
|
||||||
|
|
||||||
|
fn add(self, rhs: u32) -> Self::Output {
|
||||||
|
MultiBufferRow(self.0 + rhs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Sub<u32> for MultiBufferRow {
|
||||||
|
type Output = MultiBufferRow;
|
||||||
|
|
||||||
|
fn sub(self, rhs: u32) -> Self::Output {
|
||||||
|
MultiBufferRow(self.0 - rhs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Sub<MultiBufferRow> for MultiBufferRow {
|
||||||
|
type Output = u32;
|
||||||
|
|
||||||
|
fn sub(self, rhs: MultiBufferRow) -> Self::Output {
|
||||||
|
self.0 - rhs.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MultiBufferRow {
|
||||||
|
fn saturating_sub(&self, v: u32) -> Self {
|
||||||
|
Self(self.0.saturating_sub(v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq, Hash)]
|
||||||
|
pub struct MultiBufferPoint(pub Point);
|
||||||
|
|
||||||
|
impl MultiBufferPoint {
|
||||||
|
pub fn new(row: MultiBufferRow, col: u32) -> Self {
|
||||||
|
Self(Point::new(row.0, col))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn row(&self) -> MultiBufferRow {
|
||||||
|
MultiBufferRow(self.0.row)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn row_mut(&mut self) -> &mut MultiBufferRow {
|
||||||
|
unsafe { std::mem::transmute(&mut self.0.row) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Add<Point> for MultiBufferPoint {
|
||||||
|
type Output = MultiBufferPoint;
|
||||||
|
|
||||||
|
fn add(self, rhs: Point) -> Self::Output {
|
||||||
|
MultiBufferPoint(self.0 + rhs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AddAssign<Point> for MultiBufferPoint {
|
||||||
|
fn add_assign(&mut self, rhs: Point) {
|
||||||
|
self.0 += rhs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Sub<MultiBufferPoint> for MultiBufferPoint {
|
||||||
|
type Output = Point;
|
||||||
|
|
||||||
|
fn sub(self, rhs: MultiBufferPoint) -> Self::Output {
|
||||||
|
self.0 - rhs.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Sub<Point> for MultiBufferPoint {
|
||||||
|
type Output = MultiBufferPoint;
|
||||||
|
|
||||||
|
fn sub(self, rhs: Point) -> Self::Output {
|
||||||
|
MultiBufferPoint(self.0 - rhs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl MultiBufferRow {
|
impl MultiBufferRow {
|
||||||
pub const MIN: Self = Self(0);
|
pub const MIN: Self = Self(0);
|
||||||
pub const MAX: Self = Self(u32::MAX);
|
pub const MAX: Self = Self(u32::MAX);
|
||||||
@@ -160,8 +236,8 @@ pub trait ToOffsetUtf16: 'static + fmt::Debug {
|
|||||||
fn to_offset_utf16(&self, snapshot: &MultiBufferSnapshot) -> OffsetUtf16;
|
fn to_offset_utf16(&self, snapshot: &MultiBufferSnapshot) -> OffsetUtf16;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ToPoint: 'static + fmt::Debug {
|
pub trait ToMultiBufferPoint: 'static + fmt::Debug {
|
||||||
fn to_point(&self, snapshot: &MultiBufferSnapshot) -> Point;
|
fn to_point(&self, snapshot: &MultiBufferSnapshot) -> MultiBufferPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ToPointUtf16: 'static + fmt::Debug {
|
pub trait ToPointUtf16: 'static + fmt::Debug {
|
||||||
@@ -289,7 +365,7 @@ pub struct ExcerptSummary {
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct MultiBufferRows<'a> {
|
pub struct MultiBufferRows<'a> {
|
||||||
buffer_row_range: Range<u32>,
|
buffer_row_range: Range<u32>,
|
||||||
excerpts: Cursor<'a, Excerpt, Point>,
|
excerpts: Cursor<'a, Excerpt, MultiBufferPoint>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MultiBufferChunks<'a> {
|
pub struct MultiBufferChunks<'a> {
|
||||||
@@ -842,15 +918,20 @@ impl MultiBuffer {
|
|||||||
// Panics if the given position is invalid.
|
// Panics if the given position is invalid.
|
||||||
pub fn insert_empty_line(
|
pub fn insert_empty_line(
|
||||||
&mut self,
|
&mut self,
|
||||||
position: impl ToPoint,
|
position: impl ToMultiBufferPoint,
|
||||||
space_above: bool,
|
space_above: bool,
|
||||||
space_below: bool,
|
space_below: bool,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Point {
|
) -> MultiBufferPoint {
|
||||||
let multibuffer_point = position.to_point(&self.read(cx));
|
let multibuffer_point = position.to_point(&self.read(cx));
|
||||||
if let Some(buffer) = self.as_singleton() {
|
if let Some(buffer) = self.as_singleton() {
|
||||||
buffer.update(cx, |buffer, cx| {
|
buffer.update(cx, |buffer, cx| {
|
||||||
buffer.insert_empty_line(multibuffer_point, space_above, space_below, cx)
|
MultiBufferPoint(buffer.insert_empty_line(
|
||||||
|
multibuffer_point.0,
|
||||||
|
space_above,
|
||||||
|
space_below,
|
||||||
|
cx,
|
||||||
|
))
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
let (buffer, buffer_point, _) =
|
let (buffer, buffer_point, _) =
|
||||||
@@ -1615,14 +1696,14 @@ impl MultiBuffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If point is at the end of the buffer, the last excerpt is returned
|
// If point is at the end of the buffer, the last excerpt is returned
|
||||||
pub fn point_to_buffer_point<T: ToPoint>(
|
pub fn point_to_buffer_point<T: ToMultiBufferPoint>(
|
||||||
&self,
|
&self,
|
||||||
point: T,
|
point: T,
|
||||||
cx: &AppContext,
|
cx: &AppContext,
|
||||||
) -> Option<(Model<Buffer>, Point, ExcerptId)> {
|
) -> Option<(Model<Buffer>, Point, ExcerptId)> {
|
||||||
let snapshot = self.read(cx);
|
let snapshot = self.read(cx);
|
||||||
let point = point.to_point(&snapshot);
|
let point = point.to_point(&snapshot);
|
||||||
let mut cursor = snapshot.excerpts.cursor::<Point>(&());
|
let mut cursor = snapshot.excerpts.cursor::<MultiBufferPoint>(&());
|
||||||
cursor.seek(&point, Bias::Right, &());
|
cursor.seek(&point, Bias::Right, &());
|
||||||
if cursor.item().is_none() {
|
if cursor.item().is_none() {
|
||||||
cursor.prev(&());
|
cursor.prev(&());
|
||||||
@@ -1630,7 +1711,7 @@ impl MultiBuffer {
|
|||||||
|
|
||||||
cursor.item().map(|excerpt| {
|
cursor.item().map(|excerpt| {
|
||||||
let excerpt_start = excerpt.range.context.start.to_point(&excerpt.buffer);
|
let excerpt_start = excerpt.range.context.start.to_point(&excerpt.buffer);
|
||||||
let buffer_point = excerpt_start + point - *cursor.start();
|
let buffer_point = excerpt_start + (point - *cursor.start());
|
||||||
let buffer = self.buffers.borrow()[&excerpt.buffer_id].buffer.clone();
|
let buffer = self.buffers.borrow()[&excerpt.buffer_id].buffer.clone();
|
||||||
|
|
||||||
(buffer, buffer_point, excerpt.id)
|
(buffer, buffer_point, excerpt.id)
|
||||||
@@ -2481,8 +2562,10 @@ impl MultiBufferSnapshot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_line_blank(&self, row: MultiBufferRow) -> bool {
|
pub fn is_line_blank(&self, row: MultiBufferRow) -> bool {
|
||||||
self.text_for_range(Point::new(row.0, 0)..Point::new(row.0, self.line_len(row)))
|
self.text_for_range(
|
||||||
.all(|chunk| chunk.matches(|c: char| !c.is_whitespace()).next().is_none())
|
MultiBufferPoint::new(row, 0)..MultiBufferPoint::new(row, self.line_len(row)),
|
||||||
|
)
|
||||||
|
.all(|chunk| chunk.matches(|c: char| !c.is_whitespace()).next().is_none())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn contains_str_at<T>(&self, position: T, needle: &str) -> bool
|
pub fn contains_str_at<T>(&self, position: T, needle: &str) -> bool
|
||||||
@@ -2579,18 +2662,18 @@ impl MultiBufferSnapshot {
|
|||||||
cursor.start() + overshoot
|
cursor.start() + overshoot
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clip_point(&self, point: Point, bias: Bias) -> Point {
|
pub fn clip_point(&self, point: MultiBufferPoint, bias: Bias) -> MultiBufferPoint {
|
||||||
if let Some((_, _, buffer)) = self.as_singleton() {
|
if let Some((_, _, buffer)) = self.as_singleton() {
|
||||||
return buffer.clip_point(point, bias);
|
return MultiBufferPoint(buffer.clip_point(point.0, bias));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut cursor = self.excerpts.cursor::<Point>(&());
|
let mut cursor = self.excerpts.cursor::<MultiBufferPoint>(&());
|
||||||
cursor.seek(&point, Bias::Right, &());
|
cursor.seek(&point, Bias::Right, &());
|
||||||
let overshoot = if let Some(excerpt) = cursor.item() {
|
let overshoot = if let Some(excerpt) = cursor.item() {
|
||||||
let excerpt_start = excerpt.range.context.start.to_point(&excerpt.buffer);
|
let excerpt_start = excerpt.range.context.start.to_point(&excerpt.buffer);
|
||||||
let buffer_point = excerpt
|
let buffer_point = excerpt
|
||||||
.buffer
|
.buffer
|
||||||
.clip_point(excerpt_start + (point - cursor.start()), bias);
|
.clip_point(excerpt_start + (point - *cursor.start()), bias);
|
||||||
buffer_point.saturating_sub(excerpt_start)
|
buffer_point.saturating_sub(excerpt_start)
|
||||||
} else {
|
} else {
|
||||||
Point::zero()
|
Point::zero()
|
||||||
@@ -2708,12 +2791,12 @@ impl MultiBufferSnapshot {
|
|||||||
chunks
|
chunks
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn offset_to_point(&self, offset: usize) -> Point {
|
pub fn offset_to_point(&self, offset: usize) -> MultiBufferPoint {
|
||||||
if let Some((_, _, buffer)) = self.as_singleton() {
|
if let Some((_, _, buffer)) = self.as_singleton() {
|
||||||
return buffer.offset_to_point(offset);
|
return MultiBufferPoint(buffer.offset_to_point(offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut cursor = self.excerpts.cursor::<(usize, Point)>(&());
|
let mut cursor = self.excerpts.cursor::<(usize, MultiBufferPoint)>(&());
|
||||||
cursor.seek(&offset, Bias::Right, &());
|
cursor.seek(&offset, Bias::Right, &());
|
||||||
if let Some(excerpt) = cursor.item() {
|
if let Some(excerpt) = cursor.item() {
|
||||||
let (start_offset, start_point) = cursor.start();
|
let (start_offset, start_point) = cursor.start();
|
||||||
@@ -2725,7 +2808,7 @@ impl MultiBufferSnapshot {
|
|||||||
.offset_to_point(excerpt_start_offset + overshoot);
|
.offset_to_point(excerpt_start_offset + overshoot);
|
||||||
*start_point + (buffer_point - excerpt_start_point)
|
*start_point + (buffer_point - excerpt_start_point)
|
||||||
} else {
|
} else {
|
||||||
self.excerpts.summary().text.lines
|
MultiBufferPoint(self.excerpts.summary().text.lines)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2750,16 +2833,16 @@ impl MultiBufferSnapshot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn point_to_point_utf16(&self, point: Point) -> PointUtf16 {
|
pub fn point_to_point_utf16(&self, point: MultiBufferPoint) -> PointUtf16 {
|
||||||
if let Some((_, _, buffer)) = self.as_singleton() {
|
if let Some((_, _, buffer)) = self.as_singleton() {
|
||||||
return buffer.point_to_point_utf16(point);
|
return buffer.point_to_point_utf16(point.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut cursor = self.excerpts.cursor::<(Point, PointUtf16)>(&());
|
let mut cursor = self.excerpts.cursor::<(MultiBufferPoint, PointUtf16)>(&());
|
||||||
cursor.seek(&point, Bias::Right, &());
|
cursor.seek(&point, Bias::Right, &());
|
||||||
if let Some(excerpt) = cursor.item() {
|
if let Some(excerpt) = cursor.item() {
|
||||||
let (start_offset, start_point) = cursor.start();
|
let (start_offset, start_point) = cursor.start();
|
||||||
let overshoot = point - start_offset;
|
let overshoot = point - *start_offset;
|
||||||
let excerpt_start_point = excerpt.range.context.start.to_point(&excerpt.buffer);
|
let excerpt_start_point = excerpt.range.context.start.to_point(&excerpt.buffer);
|
||||||
let excerpt_start_point_utf16 =
|
let excerpt_start_point_utf16 =
|
||||||
excerpt.range.context.start.to_point_utf16(&excerpt.buffer);
|
excerpt.range.context.start.to_point_utf16(&excerpt.buffer);
|
||||||
@@ -2772,16 +2855,16 @@ impl MultiBufferSnapshot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn point_to_offset(&self, point: Point) -> usize {
|
pub fn point_to_offset(&self, point: MultiBufferPoint) -> usize {
|
||||||
if let Some((_, _, buffer)) = self.as_singleton() {
|
if let Some((_, _, buffer)) = self.as_singleton() {
|
||||||
return buffer.point_to_offset(point);
|
return buffer.point_to_offset(point.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut cursor = self.excerpts.cursor::<(Point, usize)>(&());
|
let mut cursor = self.excerpts.cursor::<(MultiBufferPoint, usize)>(&());
|
||||||
cursor.seek(&point, Bias::Right, &());
|
cursor.seek(&point, Bias::Right, &());
|
||||||
if let Some(excerpt) = cursor.item() {
|
if let Some(excerpt) = cursor.item() {
|
||||||
let (start_point, start_offset) = cursor.start();
|
let (start_point, start_offset) = cursor.start();
|
||||||
let overshoot = point - start_point;
|
let overshoot = point - *start_point;
|
||||||
let excerpt_start_offset = excerpt.range.context.start.to_offset(&excerpt.buffer);
|
let excerpt_start_offset = excerpt.range.context.start.to_offset(&excerpt.buffer);
|
||||||
let excerpt_start_point = excerpt.range.context.start.to_point(&excerpt.buffer);
|
let excerpt_start_point = excerpt.range.context.start.to_point(&excerpt.buffer);
|
||||||
let buffer_offset = excerpt
|
let buffer_offset = excerpt
|
||||||
@@ -2882,19 +2965,19 @@ impl MultiBufferSnapshot {
|
|||||||
|
|
||||||
pub fn suggested_indents(
|
pub fn suggested_indents(
|
||||||
&self,
|
&self,
|
||||||
rows: impl IntoIterator<Item = u32>,
|
rows: impl IntoIterator<Item = MultiBufferRow>,
|
||||||
cx: &AppContext,
|
cx: &AppContext,
|
||||||
) -> BTreeMap<MultiBufferRow, IndentSize> {
|
) -> BTreeMap<MultiBufferRow, IndentSize> {
|
||||||
let mut result = BTreeMap::new();
|
let mut result = BTreeMap::new();
|
||||||
|
|
||||||
let mut rows_for_excerpt = Vec::new();
|
let mut rows_for_excerpt = Vec::new();
|
||||||
let mut cursor = self.excerpts.cursor::<Point>(&());
|
let mut cursor = self.excerpts.cursor::<MultiBufferPoint>(&());
|
||||||
let mut rows = rows.into_iter().peekable();
|
let mut rows = rows.into_iter().peekable();
|
||||||
let mut prev_row = u32::MAX;
|
let mut prev_row = MultiBufferRow::MAX;
|
||||||
let mut prev_language_indent_size = IndentSize::default();
|
let mut prev_language_indent_size = IndentSize::default();
|
||||||
|
|
||||||
while let Some(row) = rows.next() {
|
while let Some(row) = rows.next() {
|
||||||
cursor.seek(&Point::new(row, 0), Bias::Right, &());
|
cursor.seek(&MultiBufferPoint::new(row, 0), Bias::Right, &());
|
||||||
let excerpt = match cursor.item() {
|
let excerpt = match cursor.item() {
|
||||||
Some(excerpt) => excerpt,
|
Some(excerpt) => excerpt,
|
||||||
_ => continue,
|
_ => continue,
|
||||||
@@ -2906,17 +2989,17 @@ impl MultiBufferSnapshot {
|
|||||||
} else {
|
} else {
|
||||||
excerpt
|
excerpt
|
||||||
.buffer
|
.buffer
|
||||||
.language_indent_size_at(Point::new(row, 0), cx)
|
.language_indent_size_at(Point::new(row - cursor.start().row(), 0), cx)
|
||||||
};
|
};
|
||||||
prev_language_indent_size = single_indent_size;
|
prev_language_indent_size = single_indent_size;
|
||||||
prev_row = row;
|
prev_row = row;
|
||||||
|
|
||||||
let start_buffer_row = excerpt.range.context.start.to_point(&excerpt.buffer).row;
|
let start_buffer_row = excerpt.range.context.start.to_point(&excerpt.buffer).row;
|
||||||
let start_multibuffer_row = cursor.start().row;
|
let start_multibuffer_row = cursor.start().row();
|
||||||
|
|
||||||
rows_for_excerpt.push(row);
|
rows_for_excerpt.push(row);
|
||||||
while let Some(next_row) = rows.peek().copied() {
|
while let Some(next_row) = rows.peek().copied() {
|
||||||
if cursor.end(&()).row > next_row {
|
if cursor.end(&()).row() > next_row {
|
||||||
rows_for_excerpt.push(next_row);
|
rows_for_excerpt.push(next_row);
|
||||||
rows.next();
|
rows.next();
|
||||||
} else {
|
} else {
|
||||||
@@ -2926,16 +3009,13 @@ impl MultiBufferSnapshot {
|
|||||||
|
|
||||||
let buffer_rows = rows_for_excerpt
|
let buffer_rows = rows_for_excerpt
|
||||||
.drain(..)
|
.drain(..)
|
||||||
.map(|row| start_buffer_row + row - start_multibuffer_row);
|
.map(|row| start_buffer_row + (row - start_multibuffer_row));
|
||||||
let buffer_indents = excerpt
|
let buffer_indents = excerpt
|
||||||
.buffer
|
.buffer
|
||||||
.suggested_indents(buffer_rows, single_indent_size);
|
.suggested_indents(buffer_rows, single_indent_size);
|
||||||
let multibuffer_indents = buffer_indents.into_iter().map(|(row, indent)| {
|
let multibuffer_indents = buffer_indents
|
||||||
(
|
.into_iter()
|
||||||
MultiBufferRow(start_multibuffer_row + row - start_buffer_row),
|
.map(|(row, indent)| (start_multibuffer_row + row - start_buffer_row, indent));
|
||||||
indent,
|
|
||||||
)
|
|
||||||
});
|
|
||||||
result.extend(multibuffer_indents);
|
result.extend(multibuffer_indents);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2959,11 +3039,11 @@ impl MultiBufferSnapshot {
|
|||||||
let mut indent = self.indent_size_for_line(row).chars().collect::<String>();
|
let mut indent = self.indent_size_for_line(row).chars().collect::<String>();
|
||||||
|
|
||||||
if self.settings_at(0, cx).extend_comment_on_newline {
|
if self.settings_at(0, cx).extend_comment_on_newline {
|
||||||
if let Some(language_scope) = self.language_scope_at(Point::new(row.0, 0)) {
|
if let Some(language_scope) = self.language_scope_at(MultiBufferPoint::new(row, 0)) {
|
||||||
let delimiters = language_scope.line_comment_prefixes();
|
let delimiters = language_scope.line_comment_prefixes();
|
||||||
for delimiter in delimiters {
|
for delimiter in delimiters {
|
||||||
if *self
|
if *self
|
||||||
.chars_at(Point::new(row.0, indent.len() as u32))
|
.chars_at(MultiBufferPoint::new(row, indent.len() as u32))
|
||||||
.take(delimiter.chars().count())
|
.take(delimiter.chars().count())
|
||||||
.collect::<String>()
|
.collect::<String>()
|
||||||
.as_str()
|
.as_str()
|
||||||
@@ -3001,14 +3081,14 @@ impl MultiBufferSnapshot {
|
|||||||
&self,
|
&self,
|
||||||
row: MultiBufferRow,
|
row: MultiBufferRow,
|
||||||
) -> Option<(&BufferSnapshot, Range<Point>)> {
|
) -> Option<(&BufferSnapshot, Range<Point>)> {
|
||||||
let mut cursor = self.excerpts.cursor::<Point>(&());
|
let mut cursor = self.excerpts.cursor::<MultiBufferPoint>(&());
|
||||||
let point = Point::new(row.0, 0);
|
let point = MultiBufferPoint::new(row, 0);
|
||||||
cursor.seek(&point, Bias::Right, &());
|
cursor.seek(&point, Bias::Right, &());
|
||||||
if cursor.item().is_none() && *cursor.start() == point {
|
if cursor.item().is_none() && *cursor.start() == point {
|
||||||
cursor.prev(&());
|
cursor.prev(&());
|
||||||
}
|
}
|
||||||
if let Some(excerpt) = cursor.item() {
|
if let Some(excerpt) = cursor.item() {
|
||||||
let overshoot = row.0 - cursor.start().row;
|
let overshoot = row - cursor.start().row();
|
||||||
let excerpt_start = excerpt.range.context.start.to_point(&excerpt.buffer);
|
let excerpt_start = excerpt.range.context.start.to_point(&excerpt.buffer);
|
||||||
let excerpt_end = excerpt.range.context.end.to_point(&excerpt.buffer);
|
let excerpt_end = excerpt.range.context.end.to_point(&excerpt.buffer);
|
||||||
let buffer_row = excerpt_start.row + overshoot;
|
let buffer_row = excerpt_start.row + overshoot;
|
||||||
@@ -3022,8 +3102,8 @@ impl MultiBufferSnapshot {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn max_point(&self) -> Point {
|
pub fn max_point(&self) -> MultiBufferPoint {
|
||||||
self.text_summary().lines
|
MultiBufferPoint(self.text_summary().lines)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn text_summary(&self) -> TextSummary {
|
pub fn text_summary(&self) -> TextSummary {
|
||||||
@@ -3178,7 +3258,7 @@ impl MultiBufferSnapshot {
|
|||||||
|
|
||||||
pub fn dimensions_from_points<'a, D>(
|
pub fn dimensions_from_points<'a, D>(
|
||||||
&'a self,
|
&'a self,
|
||||||
points: impl 'a + IntoIterator<Item = Point>,
|
points: impl 'a + IntoIterator<Item = MultiBufferPoint>,
|
||||||
) -> impl 'a + Iterator<Item = D>
|
) -> impl 'a + Iterator<Item = D>
|
||||||
where
|
where
|
||||||
D: TextDimension,
|
D: TextDimension,
|
||||||
@@ -3190,7 +3270,9 @@ impl MultiBufferSnapshot {
|
|||||||
let point = points.next()?;
|
let point = points.next()?;
|
||||||
|
|
||||||
// Clear the memoized source start if the point is in a different excerpt than previous.
|
// Clear the memoized source start if the point is in a different excerpt than previous.
|
||||||
if memoized_source_start.map_or(false, |_| point >= cursor.end(&()).lines) {
|
if memoized_source_start
|
||||||
|
.map_or(false, |_| point >= MultiBufferPoint(cursor.end(&()).lines))
|
||||||
|
{
|
||||||
memoized_source_start = None;
|
memoized_source_start = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3214,9 +3296,9 @@ impl MultiBufferSnapshot {
|
|||||||
|
|
||||||
// If the point lands within its excerpt, calculate and add the overshoot in dimension D.
|
// If the point lands within its excerpt, calculate and add the overshoot in dimension D.
|
||||||
if let Some(excerpt) = cursor.item() {
|
if let Some(excerpt) = cursor.item() {
|
||||||
let overshoot = point - cursor.start().lines;
|
let overshoot = point - MultiBufferPoint(cursor.start().lines);
|
||||||
if !overshoot.is_zero() {
|
if !overshoot.is_zero() {
|
||||||
let end_in_excerpt = source_start + overshoot;
|
let end_in_excerpt = overshoot + source_start;
|
||||||
output.add_assign(
|
output.add_assign(
|
||||||
&excerpt
|
&excerpt
|
||||||
.buffer
|
.buffer
|
||||||
@@ -3495,7 +3577,7 @@ impl MultiBufferSnapshot {
|
|||||||
};
|
};
|
||||||
let bounds = (start, end);
|
let bounds = (start, end);
|
||||||
|
|
||||||
let mut cursor = self.excerpts.cursor::<(usize, Point)>(&());
|
let mut cursor = self.excerpts.cursor::<(usize, MultiBufferPoint)>(&());
|
||||||
cursor.seek(&start_offset, Bias::Right, &());
|
cursor.seek(&start_offset, Bias::Right, &());
|
||||||
if cursor.item().is_none() {
|
if cursor.item().is_none() {
|
||||||
cursor.prev(&());
|
cursor.prev(&());
|
||||||
@@ -3530,7 +3612,7 @@ impl MultiBufferSnapshot {
|
|||||||
buffer_id: prev_excerpt.buffer_id,
|
buffer_id: prev_excerpt.buffer_id,
|
||||||
range: prev_excerpt.range.clone(),
|
range: prev_excerpt.range.clone(),
|
||||||
});
|
});
|
||||||
let row = MultiBufferRow(cursor.start().1.row);
|
let row = cursor.start().1.row();
|
||||||
|
|
||||||
cursor.next(&());
|
cursor.next(&());
|
||||||
|
|
||||||
@@ -3730,7 +3812,8 @@ impl MultiBufferSnapshot {
|
|||||||
.flat_map(move |(excerpt, excerpt_offset)| {
|
.flat_map(move |(excerpt, excerpt_offset)| {
|
||||||
let excerpt_buffer_start_row =
|
let excerpt_buffer_start_row =
|
||||||
excerpt.range.context.start.to_point(&excerpt.buffer).row;
|
excerpt.range.context.start.to_point(&excerpt.buffer).row;
|
||||||
let excerpt_offset_row = crate::ToPoint::to_point(&excerpt_offset, self).row;
|
let excerpt_offset_row =
|
||||||
|
crate::ToMultiBufferPoint::to_point(&excerpt_offset, self).row();
|
||||||
|
|
||||||
excerpt
|
excerpt
|
||||||
.buffer
|
.buffer
|
||||||
@@ -3747,8 +3830,7 @@ impl MultiBufferSnapshot {
|
|||||||
excerpt_offset_row + (indent_guide.end_row - excerpt_buffer_start_row);
|
excerpt_offset_row + (indent_guide.end_row - excerpt_buffer_start_row);
|
||||||
|
|
||||||
MultiBufferIndentGuide {
|
MultiBufferIndentGuide {
|
||||||
multibuffer_row_range: MultiBufferRow(start_row)
|
multibuffer_row_range: start_row..end_row,
|
||||||
..MultiBufferRow(end_row),
|
|
||||||
buffer: indent_guide,
|
buffer: indent_guide,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -3866,9 +3948,9 @@ impl MultiBufferSnapshot {
|
|||||||
&self,
|
&self,
|
||||||
row_range: Range<MultiBufferRow>,
|
row_range: Range<MultiBufferRow>,
|
||||||
) -> impl Iterator<Item = MultiBufferDiffHunk> + '_ {
|
) -> impl Iterator<Item = MultiBufferDiffHunk> + '_ {
|
||||||
let mut cursor = self.excerpts.cursor::<Point>(&());
|
let mut cursor = self.excerpts.cursor::<MultiBufferPoint>(&());
|
||||||
|
|
||||||
cursor.seek(&Point::new(row_range.end.0, 0), Bias::Left, &());
|
cursor.seek(&MultiBufferPoint::new(row_range.end, 0), Bias::Left, &());
|
||||||
if cursor.item().is_none() {
|
if cursor.item().is_none() {
|
||||||
cursor.prev(&());
|
cursor.prev(&());
|
||||||
}
|
}
|
||||||
@@ -3877,7 +3959,7 @@ impl MultiBufferSnapshot {
|
|||||||
let excerpt = cursor.item()?;
|
let excerpt = cursor.item()?;
|
||||||
let multibuffer_start = *cursor.start();
|
let multibuffer_start = *cursor.start();
|
||||||
let multibuffer_end = multibuffer_start + excerpt.text_summary.lines;
|
let multibuffer_end = multibuffer_start + excerpt.text_summary.lines;
|
||||||
if multibuffer_start.row >= row_range.end.0 {
|
if multibuffer_start.row() >= row_range.end {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3886,15 +3968,15 @@ impl MultiBufferSnapshot {
|
|||||||
let excerpt_start_point = buffer_start.to_point(&excerpt.buffer);
|
let excerpt_start_point = buffer_start.to_point(&excerpt.buffer);
|
||||||
let excerpt_end_point = excerpt_start_point + excerpt.text_summary.lines;
|
let excerpt_end_point = excerpt_start_point + excerpt.text_summary.lines;
|
||||||
|
|
||||||
if row_range.start.0 > multibuffer_start.row {
|
if row_range.start > multibuffer_start.row() {
|
||||||
let buffer_start_point =
|
let buffer_start_point =
|
||||||
excerpt_start_point + Point::new(row_range.start.0 - multibuffer_start.row, 0);
|
excerpt_start_point + Point::new(row_range.start - multibuffer_start.row(), 0);
|
||||||
buffer_start = excerpt.buffer.anchor_before(buffer_start_point);
|
buffer_start = excerpt.buffer.anchor_before(buffer_start_point);
|
||||||
}
|
}
|
||||||
|
|
||||||
if row_range.end.0 < multibuffer_end.row {
|
if row_range.end < multibuffer_end.row() {
|
||||||
let buffer_end_point =
|
let buffer_end_point =
|
||||||
excerpt_start_point + Point::new(row_range.end.0 - multibuffer_start.row, 0);
|
excerpt_start_point + Point::new(row_range.end - multibuffer_start.row(), 0);
|
||||||
buffer_end = excerpt.buffer.anchor_before(buffer_end_point);
|
buffer_end = excerpt.buffer.anchor_before(buffer_end_point);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3902,9 +3984,9 @@ impl MultiBufferSnapshot {
|
|||||||
.buffer
|
.buffer
|
||||||
.git_diff_hunks_intersecting_range_rev(buffer_start..buffer_end)
|
.git_diff_hunks_intersecting_range_rev(buffer_start..buffer_end)
|
||||||
.map(move |hunk| {
|
.map(move |hunk| {
|
||||||
let start = multibuffer_start.row
|
let start = multibuffer_start.row()
|
||||||
+ hunk.row_range.start.saturating_sub(excerpt_start_point.row);
|
+ hunk.row_range.start.saturating_sub(excerpt_start_point.row);
|
||||||
let end = multibuffer_start.row
|
let end = multibuffer_start.row()
|
||||||
+ hunk
|
+ hunk
|
||||||
.row_range
|
.row_range
|
||||||
.end
|
.end
|
||||||
@@ -3912,7 +3994,7 @@ impl MultiBufferSnapshot {
|
|||||||
.saturating_sub(excerpt_start_point.row);
|
.saturating_sub(excerpt_start_point.row);
|
||||||
|
|
||||||
MultiBufferDiffHunk {
|
MultiBufferDiffHunk {
|
||||||
row_range: MultiBufferRow(start)..MultiBufferRow(end),
|
row_range: start..end,
|
||||||
diff_base_byte_range: hunk.diff_base_byte_range.clone(),
|
diff_base_byte_range: hunk.diff_base_byte_range.clone(),
|
||||||
buffer_range: hunk.buffer_range.clone(),
|
buffer_range: hunk.buffer_range.clone(),
|
||||||
buffer_id: excerpt.buffer_id,
|
buffer_id: excerpt.buffer_id,
|
||||||
@@ -3930,9 +4012,9 @@ impl MultiBufferSnapshot {
|
|||||||
&self,
|
&self,
|
||||||
row_range: Range<MultiBufferRow>,
|
row_range: Range<MultiBufferRow>,
|
||||||
) -> impl Iterator<Item = MultiBufferDiffHunk> + '_ {
|
) -> impl Iterator<Item = MultiBufferDiffHunk> + '_ {
|
||||||
let mut cursor = self.excerpts.cursor::<Point>(&());
|
let mut cursor = self.excerpts.cursor::<MultiBufferPoint>(&());
|
||||||
|
|
||||||
cursor.seek(&Point::new(row_range.start.0, 0), Bias::Left, &());
|
cursor.seek(&MultiBufferPoint::new(row_range.start, 0), Bias::Left, &());
|
||||||
|
|
||||||
std::iter::from_fn(move || {
|
std::iter::from_fn(move || {
|
||||||
let excerpt = cursor.item()?;
|
let excerpt = cursor.item()?;
|
||||||
@@ -3941,20 +4023,20 @@ impl MultiBufferSnapshot {
|
|||||||
let mut buffer_start = excerpt.range.context.start;
|
let mut buffer_start = excerpt.range.context.start;
|
||||||
let mut buffer_end = excerpt.range.context.end;
|
let mut buffer_end = excerpt.range.context.end;
|
||||||
|
|
||||||
let excerpt_rows = match multibuffer_start.row.cmp(&row_range.end.0) {
|
let excerpt_rows = match multibuffer_start.row().cmp(&row_range.end) {
|
||||||
cmp::Ordering::Less => {
|
cmp::Ordering::Less => {
|
||||||
let excerpt_start_point = buffer_start.to_point(&excerpt.buffer);
|
let excerpt_start_point = buffer_start.to_point(&excerpt.buffer);
|
||||||
let excerpt_end_point = excerpt_start_point + excerpt.text_summary.lines;
|
let excerpt_end_point = excerpt_start_point + excerpt.text_summary.lines;
|
||||||
|
|
||||||
if row_range.start.0 > multibuffer_start.row {
|
if row_range.start > multibuffer_start.row() {
|
||||||
let buffer_start_point = excerpt_start_point
|
let buffer_start_point = excerpt_start_point
|
||||||
+ Point::new(row_range.start.0 - multibuffer_start.row, 0);
|
+ Point::new(row_range.start - multibuffer_start.row(), 0);
|
||||||
buffer_start = excerpt.buffer.anchor_before(buffer_start_point);
|
buffer_start = excerpt.buffer.anchor_before(buffer_start_point);
|
||||||
}
|
}
|
||||||
|
|
||||||
if row_range.end.0 < multibuffer_end.row {
|
if row_range.end < multibuffer_end.row() {
|
||||||
let buffer_end_point = excerpt_start_point
|
let buffer_end_point = excerpt_start_point
|
||||||
+ Point::new(row_range.end.0 - multibuffer_start.row, 0);
|
+ Point::new(row_range.end - multibuffer_start.row(), 0);
|
||||||
buffer_end = excerpt.buffer.anchor_before(buffer_end_point);
|
buffer_end = excerpt.buffer.anchor_before(buffer_end_point);
|
||||||
}
|
}
|
||||||
excerpt_start_point.row..excerpt_end_point.row
|
excerpt_start_point.row..excerpt_end_point.row
|
||||||
@@ -3973,15 +4055,15 @@ impl MultiBufferSnapshot {
|
|||||||
let buffer_range = if excerpt_rows.start == 0 && excerpt_rows.end == 0 {
|
let buffer_range = if excerpt_rows.start == 0 && excerpt_rows.end == 0 {
|
||||||
MultiBufferRow(0)..MultiBufferRow(1)
|
MultiBufferRow(0)..MultiBufferRow(1)
|
||||||
} else {
|
} else {
|
||||||
let start = multibuffer_start.row
|
let start = multibuffer_start.row()
|
||||||
+ hunk.row_range.start.saturating_sub(excerpt_rows.start);
|
+ hunk.row_range.start.saturating_sub(excerpt_rows.start);
|
||||||
let end = multibuffer_start.row
|
let end = multibuffer_start.row()
|
||||||
+ hunk
|
+ hunk
|
||||||
.row_range
|
.row_range
|
||||||
.end
|
.end
|
||||||
.min(excerpt_rows.end + 1)
|
.min(excerpt_rows.end + 1)
|
||||||
.saturating_sub(excerpt_rows.start);
|
.saturating_sub(excerpt_rows.start);
|
||||||
MultiBufferRow(start)..MultiBufferRow(end)
|
start..end
|
||||||
};
|
};
|
||||||
MultiBufferDiffHunk {
|
MultiBufferDiffHunk {
|
||||||
row_range: buffer_range,
|
row_range: buffer_range,
|
||||||
@@ -4899,9 +4981,9 @@ impl<'a> sum_tree::SeekTarget<'a, ExcerptSummary, ExcerptSummary> for usize {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> sum_tree::SeekTarget<'a, ExcerptSummary, TextSummary> for Point {
|
impl<'a> sum_tree::SeekTarget<'a, ExcerptSummary, TextSummary> for MultiBufferPoint {
|
||||||
fn cmp(&self, cursor_location: &TextSummary, _: &()) -> cmp::Ordering {
|
fn cmp(&self, cursor_location: &TextSummary, _: &()) -> cmp::Ordering {
|
||||||
Ord::cmp(self, &cursor_location.lines)
|
Ord::cmp(self, &MultiBufferPoint(cursor_location.lines))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4927,7 +5009,7 @@ impl<'a> sum_tree::Dimension<'a, ExcerptSummary> for OffsetUtf16 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> sum_tree::Dimension<'a, ExcerptSummary> for Point {
|
impl<'a> sum_tree::Dimension<'a, ExcerptSummary> for MultiBufferPoint {
|
||||||
fn zero(_cx: &()) -> Self {
|
fn zero(_cx: &()) -> Self {
|
||||||
Default::default()
|
Default::default()
|
||||||
}
|
}
|
||||||
@@ -4972,7 +5054,7 @@ impl<'a> MultiBufferRows<'a> {
|
|||||||
self.buffer_row_range = 0..0;
|
self.buffer_row_range = 0..0;
|
||||||
|
|
||||||
self.excerpts
|
self.excerpts
|
||||||
.seek_forward(&Point::new(row.0, 0), Bias::Right, &());
|
.seek_forward(&MultiBufferPoint::new(row, 0), Bias::Right, &());
|
||||||
if self.excerpts.item().is_none() {
|
if self.excerpts.item().is_none() {
|
||||||
self.excerpts.prev(&());
|
self.excerpts.prev(&());
|
||||||
|
|
||||||
@@ -4983,7 +5065,7 @@ impl<'a> MultiBufferRows<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(excerpt) = self.excerpts.item() {
|
if let Some(excerpt) = self.excerpts.item() {
|
||||||
let overshoot = row.0 - self.excerpts.start().row;
|
let overshoot = row - self.excerpts.start().row();
|
||||||
let excerpt_start = excerpt.range.context.start.to_point(&excerpt.buffer).row;
|
let excerpt_start = excerpt.range.context.start.to_point(&excerpt.buffer).row;
|
||||||
self.buffer_row_range.start = excerpt_start + overshoot;
|
self.buffer_row_range.start = excerpt_start + overshoot;
|
||||||
self.buffer_row_range.end = excerpt_start + excerpt.text_summary.lines.row + 1;
|
self.buffer_row_range.end = excerpt_start + excerpt.text_summary.lines.row + 1;
|
||||||
@@ -5189,7 +5271,7 @@ impl<'a> Iterator for ExcerptChunks<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToOffset for Point {
|
impl ToOffset for MultiBufferPoint {
|
||||||
fn to_offset<'a>(&self, snapshot: &MultiBufferSnapshot) -> usize {
|
fn to_offset<'a>(&self, snapshot: &MultiBufferSnapshot) -> usize {
|
||||||
snapshot.point_to_offset(*self)
|
snapshot.point_to_offset(*self)
|
||||||
}
|
}
|
||||||
@@ -5226,14 +5308,14 @@ impl ToOffsetUtf16 for usize {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToPoint for usize {
|
impl ToMultiBufferPoint for usize {
|
||||||
fn to_point<'a>(&self, snapshot: &MultiBufferSnapshot) -> Point {
|
fn to_point<'a>(&self, snapshot: &MultiBufferSnapshot) -> MultiBufferPoint {
|
||||||
snapshot.offset_to_point(*self)
|
snapshot.offset_to_point(*self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToPoint for Point {
|
impl ToMultiBufferPoint for MultiBufferPoint {
|
||||||
fn to_point<'a>(&self, _: &MultiBufferSnapshot) -> Point {
|
fn to_point<'a>(&self, _: &MultiBufferSnapshot) -> MultiBufferPoint {
|
||||||
*self
|
*self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5244,7 +5326,7 @@ impl ToPointUtf16 for usize {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToPointUtf16 for Point {
|
impl ToPointUtf16 for MultiBufferPoint {
|
||||||
fn to_point_utf16<'a>(&self, snapshot: &MultiBufferSnapshot) -> PointUtf16 {
|
fn to_point_utf16<'a>(&self, snapshot: &MultiBufferSnapshot) -> PointUtf16 {
|
||||||
snapshot.point_to_point_utf16(*self)
|
snapshot.point_to_point_utf16(*self)
|
||||||
}
|
}
|
||||||
@@ -5481,7 +5563,10 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
boundaries_in_range(Point::new(0, 0)..Point::new(4, 2), &snapshot),
|
boundaries_in_range(
|
||||||
|
MultiBufferPoint(Point::new(0, 0))..MultiBufferPoint(Point::new(4, 2)),
|
||||||
|
&snapshot
|
||||||
|
),
|
||||||
&[
|
&[
|
||||||
(MultiBufferRow(0), "bbbb\nccccc".to_string(), true),
|
(MultiBufferRow(0), "bbbb\nccccc".to_string(), true),
|
||||||
(MultiBufferRow(2), "ddd\neeee".to_string(), false),
|
(MultiBufferRow(2), "ddd\neeee".to_string(), false),
|
||||||
@@ -5489,35 +5574,59 @@ mod tests {
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
boundaries_in_range(Point::new(0, 0)..Point::new(2, 0), &snapshot),
|
boundaries_in_range(
|
||||||
|
MultiBufferPoint(Point::new(0, 0))..MultiBufferPoint(Point::new(2, 0)),
|
||||||
|
&snapshot
|
||||||
|
),
|
||||||
&[(MultiBufferRow(0), "bbbb\nccccc".to_string(), true)]
|
&[(MultiBufferRow(0), "bbbb\nccccc".to_string(), true)]
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
boundaries_in_range(Point::new(1, 0)..Point::new(1, 5), &snapshot),
|
boundaries_in_range(
|
||||||
|
MultiBufferPoint(Point::new(1, 0))..MultiBufferPoint(Point::new(1, 5)),
|
||||||
|
&snapshot
|
||||||
|
),
|
||||||
&[]
|
&[]
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
boundaries_in_range(Point::new(1, 0)..Point::new(2, 0), &snapshot),
|
boundaries_in_range(
|
||||||
|
MultiBufferPoint(Point::new(1, 0))..MultiBufferPoint(Point::new(2, 0)),
|
||||||
|
&snapshot
|
||||||
|
),
|
||||||
&[]
|
&[]
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
boundaries_in_range(Point::new(1, 0)..Point::new(4, 0), &snapshot),
|
boundaries_in_range(
|
||||||
|
MultiBufferPoint(Point::new(1, 0))..MultiBufferPoint(Point::new(4, 0)),
|
||||||
|
&snapshot
|
||||||
|
),
|
||||||
&[(MultiBufferRow(2), "ddd\neeee".to_string(), false)]
|
&[(MultiBufferRow(2), "ddd\neeee".to_string(), false)]
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
boundaries_in_range(Point::new(1, 0)..Point::new(4, 0), &snapshot),
|
boundaries_in_range(
|
||||||
|
MultiBufferPoint(Point::new(1, 0))..MultiBufferPoint(Point::new(4, 0)),
|
||||||
|
&snapshot
|
||||||
|
),
|
||||||
&[(MultiBufferRow(2), "ddd\neeee".to_string(), false)]
|
&[(MultiBufferRow(2), "ddd\neeee".to_string(), false)]
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
boundaries_in_range(Point::new(2, 0)..Point::new(3, 0), &snapshot),
|
boundaries_in_range(
|
||||||
|
MultiBufferPoint(Point::new(2, 0))..MultiBufferPoint(Point::new(3, 0)),
|
||||||
|
&snapshot
|
||||||
|
),
|
||||||
&[(MultiBufferRow(2), "ddd\neeee".to_string(), false)]
|
&[(MultiBufferRow(2), "ddd\neeee".to_string(), false)]
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
boundaries_in_range(Point::new(4, 0)..Point::new(4, 2), &snapshot),
|
boundaries_in_range(
|
||||||
|
MultiBufferPoint(Point::new(4, 0))..MultiBufferPoint(Point::new(4, 2)),
|
||||||
|
&snapshot
|
||||||
|
),
|
||||||
&[(MultiBufferRow(4), "jj".to_string(), true)]
|
&[(MultiBufferRow(4), "jj".to_string(), true)]
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
boundaries_in_range(Point::new(4, 2)..Point::new(4, 2), &snapshot),
|
boundaries_in_range(
|
||||||
|
MultiBufferPoint(Point::new(4, 2))..MultiBufferPoint(Point::new(4, 2)),
|
||||||
|
&snapshot
|
||||||
|
),
|
||||||
&[]
|
&[]
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -5556,24 +5665,24 @@ mod tests {
|
|||||||
|
|
||||||
let snapshot = multibuffer.read(cx).snapshot(cx);
|
let snapshot = multibuffer.read(cx).snapshot(cx);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
snapshot.clip_point(Point::new(0, 5), Bias::Left),
|
snapshot.clip_point(MultiBufferPoint(Point::new(0, 5)), Bias::Left),
|
||||||
Point::new(0, 4)
|
MultiBufferPoint(Point::new(0, 4))
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
snapshot.clip_point(Point::new(0, 5), Bias::Right),
|
snapshot.clip_point(MultiBufferPoint(Point::new(0, 5)), Bias::Right),
|
||||||
Point::new(0, 4)
|
MultiBufferPoint(Point::new(0, 4))
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
snapshot.clip_point(Point::new(5, 1), Bias::Right),
|
snapshot.clip_point(MultiBufferPoint(Point::new(5, 1)), Bias::Right),
|
||||||
Point::new(5, 1)
|
MultiBufferPoint(Point::new(5, 1))
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
snapshot.clip_point(Point::new(5, 2), Bias::Right),
|
snapshot.clip_point(MultiBufferPoint(Point::new(5, 2)), Bias::Right),
|
||||||
Point::new(5, 2)
|
MultiBufferPoint(Point::new(5, 2))
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
snapshot.clip_point(Point::new(5, 3), Bias::Right),
|
snapshot.clip_point(MultiBufferPoint(Point::new(5, 3)), Bias::Right),
|
||||||
Point::new(5, 2)
|
MultiBufferPoint(Point::new(5, 2))
|
||||||
);
|
);
|
||||||
|
|
||||||
let snapshot = multibuffer.update(cx, |multibuffer, cx| {
|
let snapshot = multibuffer.update(cx, |multibuffer, cx| {
|
||||||
@@ -5595,7 +5704,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
fn boundaries_in_range(
|
fn boundaries_in_range(
|
||||||
range: Range<Point>,
|
range: Range<MultiBufferPoint>,
|
||||||
snapshot: &MultiBufferSnapshot,
|
snapshot: &MultiBufferSnapshot,
|
||||||
) -> Vec<(MultiBufferRow, String, bool)> {
|
) -> Vec<(MultiBufferRow, String, bool)> {
|
||||||
snapshot
|
snapshot
|
||||||
@@ -5844,9 +5953,9 @@ mod tests {
|
|||||||
.map(|range| range.to_point(&snapshot))
|
.map(|range| range.to_point(&snapshot))
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
vec![
|
vec![
|
||||||
Point::new(2, 2)..Point::new(3, 2),
|
MultiBufferPoint(Point::new(2, 2))..MultiBufferPoint(Point::new(3, 2)),
|
||||||
Point::new(6, 1)..Point::new(6, 3),
|
MultiBufferPoint(Point::new(6, 1))..MultiBufferPoint(Point::new(6, 3)),
|
||||||
Point::new(11, 0)..Point::new(11, 0)
|
MultiBufferPoint(Point::new(11, 0))..MultiBufferPoint(Point::new(11, 0))
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -5921,11 +6030,11 @@ mod tests {
|
|||||||
.map(|range| range.to_point(&snapshot))
|
.map(|range| range.to_point(&snapshot))
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
vec![
|
vec![
|
||||||
Point::new(2, 2)..Point::new(3, 2),
|
MultiBufferPoint(Point::new(2, 2))..MultiBufferPoint(Point::new(3, 2)),
|
||||||
Point::new(6, 1)..Point::new(6, 3),
|
MultiBufferPoint(Point::new(6, 1))..MultiBufferPoint(Point::new(6, 3)),
|
||||||
Point::new(11, 0)..Point::new(11, 0),
|
MultiBufferPoint(Point::new(11, 0))..MultiBufferPoint(Point::new(11, 0)),
|
||||||
Point::new(16, 1)..Point::new(17, 1),
|
MultiBufferPoint(Point::new(16, 1))..MultiBufferPoint(Point::new(17, 1)),
|
||||||
Point::new(22, 0)..Point::new(22, 2)
|
MultiBufferPoint(Point::new(22, 0))..MultiBufferPoint(Point::new(22, 2))
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -6399,7 +6508,7 @@ mod tests {
|
|||||||
let excerpt_start = excerpt_starts.next().unwrap();
|
let excerpt_start = excerpt_starts.next().unwrap();
|
||||||
let mut offset = excerpt_start.len;
|
let mut offset = excerpt_start.len;
|
||||||
let mut buffer_offset = buffer_range.start;
|
let mut buffer_offset = buffer_range.start;
|
||||||
let mut point = excerpt_start.lines;
|
let mut point = MultiBufferPoint(excerpt_start.lines);
|
||||||
let mut buffer_point = buffer_start_point;
|
let mut buffer_point = buffer_start_point;
|
||||||
let mut point_utf16 = excerpt_start.lines_utf16();
|
let mut point_utf16 = excerpt_start.lines_utf16();
|
||||||
let mut buffer_point_utf16 = buffer_start_point_utf16;
|
let mut buffer_point_utf16 = buffer_start_point_utf16;
|
||||||
@@ -6436,7 +6545,8 @@ mod tests {
|
|||||||
let buffer_right_point = buffer.clip_point(buffer_point, Bias::Right);
|
let buffer_right_point = buffer.clip_point(buffer_point, Bias::Right);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
left_point,
|
left_point,
|
||||||
excerpt_start.lines + (buffer_left_point - buffer_start_point),
|
MultiBufferPoint(excerpt_start.lines)
|
||||||
|
+ (buffer_left_point - buffer_start_point),
|
||||||
"clip_point({:?}, Left). buffer: {:?}, buffer point: {:?}",
|
"clip_point({:?}, Left). buffer: {:?}, buffer point: {:?}",
|
||||||
point,
|
point,
|
||||||
buffer_id,
|
buffer_id,
|
||||||
@@ -6444,7 +6554,8 @@ mod tests {
|
|||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
right_point,
|
right_point,
|
||||||
excerpt_start.lines + (buffer_right_point - buffer_start_point),
|
MultiBufferPoint(excerpt_start.lines)
|
||||||
|
+ (buffer_right_point - buffer_start_point),
|
||||||
"clip_point({:?}, Right). buffer: {:?}, buffer point: {:?}",
|
"clip_point({:?}, Right). buffer: {:?}, buffer point: {:?}",
|
||||||
point,
|
point,
|
||||||
buffer_id,
|
buffer_id,
|
||||||
@@ -6663,16 +6774,28 @@ mod tests {
|
|||||||
let transaction_1 = multibuffer.start_transaction_at(now, cx).unwrap();
|
let transaction_1 = multibuffer.start_transaction_at(now, cx).unwrap();
|
||||||
multibuffer.edit(
|
multibuffer.edit(
|
||||||
[
|
[
|
||||||
(Point::new(0, 0)..Point::new(0, 0), "A"),
|
(
|
||||||
(Point::new(1, 0)..Point::new(1, 0), "A"),
|
MultiBufferPoint(Point::new(0, 0))..MultiBufferPoint(Point::new(0, 0)),
|
||||||
|
"A",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
MultiBufferPoint(Point::new(1, 0))..MultiBufferPoint(Point::new(1, 0)),
|
||||||
|
"A",
|
||||||
|
),
|
||||||
],
|
],
|
||||||
None,
|
None,
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
multibuffer.edit(
|
multibuffer.edit(
|
||||||
[
|
[
|
||||||
(Point::new(0, 1)..Point::new(0, 1), "B"),
|
(
|
||||||
(Point::new(1, 1)..Point::new(1, 1), "B"),
|
MultiBufferPoint(Point::new(0, 1))..MultiBufferPoint(Point::new(0, 1)),
|
||||||
|
"B",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
MultiBufferPoint(Point::new(1, 1))..MultiBufferPoint(Point::new(1, 1)),
|
||||||
|
"B",
|
||||||
|
),
|
||||||
],
|
],
|
||||||
None,
|
None,
|
||||||
cx,
|
cx,
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use editor::{
|
|||||||
RenderBlock,
|
RenderBlock,
|
||||||
},
|
},
|
||||||
scroll::Autoscroll,
|
scroll::Autoscroll,
|
||||||
Anchor, AnchorRangeExt as _, Editor, MultiBuffer, ToPoint,
|
Anchor, AnchorRangeExt as _, Editor, MultiBuffer, ToMultiBufferPoint,
|
||||||
};
|
};
|
||||||
use futures::FutureExt as _;
|
use futures::FutureExt as _;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use anyhow::{anyhow, Result};
|
|||||||
use command_palette_hooks::CommandInterceptResult;
|
use command_palette_hooks::CommandInterceptResult;
|
||||||
use editor::{
|
use editor::{
|
||||||
actions::{SortLinesCaseInsensitive, SortLinesCaseSensitive},
|
actions::{SortLinesCaseInsensitive, SortLinesCaseSensitive},
|
||||||
Editor, ToPoint,
|
Editor, ToMultiBufferPoint,
|
||||||
};
|
};
|
||||||
use gpui::{actions, impl_actions, Action, AppContext, Global, ViewContext};
|
use gpui::{actions, impl_actions, Action, AppContext, Global, ViewContext};
|
||||||
use language::Point;
|
use language::Point;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
|
|
||||||
use editor::{scroll::Autoscroll, Editor, MultiBufferSnapshot, ToOffset, ToPoint};
|
use editor::{scroll::Autoscroll, Editor, MultiBufferSnapshot, ToMultiBufferPoint, ToOffset};
|
||||||
use gpui::{impl_actions, ViewContext};
|
use gpui::{impl_actions, ViewContext};
|
||||||
use language::{Bias, Point};
|
use language::{Bias, Point};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use crate::{
|
|||||||
state::Mode,
|
state::Mode,
|
||||||
Vim,
|
Vim,
|
||||||
};
|
};
|
||||||
use editor::{display_map::ToDisplayPoint, Bias, Editor, ToPoint};
|
use editor::{display_map::ToDisplayPoint, Bias, Editor, ToMultiBufferPoint};
|
||||||
use gpui::{actions, ViewContext};
|
use gpui::{actions, ViewContext};
|
||||||
use language::Point;
|
use language::Point;
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ use anyhow::Result;
|
|||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
use editor::{
|
use editor::{
|
||||||
movement::{self, FindRange},
|
movement::{self, FindRange},
|
||||||
Anchor, Bias, Editor, EditorEvent, EditorMode, ToPoint,
|
Anchor, Bias, Editor, EditorEvent, EditorMode, ToMultiBufferPoint,
|
||||||
};
|
};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, impl_actions, Action, AppContext, Axis, Entity, EventEmitter, KeyContext,
|
actions, impl_actions, Action, AppContext, Axis, Entity, EventEmitter, KeyContext,
|
||||||
|
|||||||
Reference in New Issue
Block a user