WIP line mode operations
This commit is contained in:
@@ -1319,7 +1319,11 @@ impl Editor {
|
||||
) {
|
||||
if self.focused && self.leader_replica_id.is_none() {
|
||||
self.buffer.update(cx, |buffer, cx| {
|
||||
buffer.set_active_selections(&self.selections.disjoint_anchors(), cx)
|
||||
buffer.set_active_selections(
|
||||
&self.selections.disjoint_anchors(),
|
||||
self.selections.line_mode,
|
||||
cx,
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5599,7 +5603,11 @@ impl View for Editor {
|
||||
self.buffer.update(cx, |buffer, cx| {
|
||||
buffer.finalize_last_transaction(cx);
|
||||
if self.leader_replica_id.is_none() {
|
||||
buffer.set_active_selections(&self.selections.disjoint_anchors(), cx);
|
||||
buffer.set_active_selections(
|
||||
&self.selections.disjoint_anchors(),
|
||||
self.selections.line_mode,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -345,12 +345,13 @@ impl EditorElement {
|
||||
scroll_top,
|
||||
scroll_left,
|
||||
bounds,
|
||||
false,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
|
||||
let mut cursors = SmallVec::<[Cursor; 32]>::new();
|
||||
for (replica_id, selections) in &layout.selections {
|
||||
for ((replica_id, line_mode), selections) in &layout.selections {
|
||||
let selection_style = style.replica_selection_style(*replica_id);
|
||||
let corner_radius = 0.15 * layout.line_height;
|
||||
|
||||
@@ -367,6 +368,7 @@ impl EditorElement {
|
||||
scroll_top,
|
||||
scroll_left,
|
||||
bounds,
|
||||
*line_mode,
|
||||
cx,
|
||||
);
|
||||
|
||||
@@ -483,6 +485,7 @@ impl EditorElement {
|
||||
scroll_top: f32,
|
||||
scroll_left: f32,
|
||||
bounds: RectF,
|
||||
line_mode: bool,
|
||||
cx: &mut PaintContext,
|
||||
) {
|
||||
if range.start != range.end {
|
||||
@@ -503,14 +506,14 @@ impl EditorElement {
|
||||
.map(|row| {
|
||||
let line_layout = &layout.line_layouts[(row - start_row) as usize];
|
||||
HighlightedRangeLine {
|
||||
start_x: if row == range.start.row() {
|
||||
start_x: if row == range.start.row() && !line_mode {
|
||||
content_origin.x()
|
||||
+ line_layout.x_for_index(range.start.column() as usize)
|
||||
- scroll_left
|
||||
} else {
|
||||
content_origin.x() - scroll_left
|
||||
},
|
||||
end_x: if row == range.end.row() {
|
||||
end_x: if row == range.end.row() && !line_mode {
|
||||
content_origin.x()
|
||||
+ line_layout.x_for_index(range.end.column() as usize)
|
||||
- scroll_left
|
||||
@@ -934,7 +937,7 @@ impl Element for EditorElement {
|
||||
);
|
||||
|
||||
let mut remote_selections = HashMap::default();
|
||||
for (replica_id, selection) in display_map
|
||||
for (replica_id, line_mode, selection) in display_map
|
||||
.buffer_snapshot
|
||||
.remote_selections_in_range(&(start_anchor.clone()..end_anchor.clone()))
|
||||
{
|
||||
@@ -944,7 +947,7 @@ impl Element for EditorElement {
|
||||
}
|
||||
|
||||
remote_selections
|
||||
.entry(replica_id)
|
||||
.entry((replica_id, line_mode))
|
||||
.or_insert(Vec::new())
|
||||
.push(crate::Selection {
|
||||
id: selection.id,
|
||||
@@ -978,7 +981,7 @@ impl Element for EditorElement {
|
||||
let local_replica_id = view.leader_replica_id.unwrap_or(view.replica_id(cx));
|
||||
|
||||
selections.push((
|
||||
local_replica_id,
|
||||
(local_replica_id, view.selections.line_mode),
|
||||
local_selections
|
||||
.into_iter()
|
||||
.map(|selection| crate::Selection {
|
||||
@@ -1237,7 +1240,7 @@ pub struct LayoutState {
|
||||
em_width: f32,
|
||||
em_advance: f32,
|
||||
highlighted_ranges: Vec<(Range<DisplayPoint>, Color)>,
|
||||
selections: Vec<(ReplicaId, Vec<text::Selection<DisplayPoint>>)>,
|
||||
selections: Vec<((ReplicaId, bool), Vec<text::Selection<DisplayPoint>>)>,
|
||||
context_menu: Option<(DisplayPoint, ElementBox)>,
|
||||
code_actions_indicator: Option<(u32, ElementBox)>,
|
||||
}
|
||||
|
||||
@@ -103,7 +103,11 @@ impl FollowableItem for Editor {
|
||||
} else {
|
||||
self.buffer.update(cx, |buffer, cx| {
|
||||
if self.focused {
|
||||
buffer.set_active_selections(&self.selections.disjoint_anchors(), cx);
|
||||
buffer.set_active_selections(
|
||||
&self.selections.disjoint_anchors(),
|
||||
self.selections.line_mode,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -509,6 +509,7 @@ impl MultiBuffer {
|
||||
pub fn set_active_selections(
|
||||
&mut self,
|
||||
selections: &[Selection<Anchor>],
|
||||
line_mode: bool,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) {
|
||||
let mut selections_by_buffer: HashMap<usize, Vec<Selection<text::Anchor>>> =
|
||||
@@ -573,7 +574,7 @@ impl MultiBuffer {
|
||||
}
|
||||
Some(selection)
|
||||
}));
|
||||
buffer.set_active_selections(merged_selections, cx);
|
||||
buffer.set_active_selections(merged_selections, line_mode, cx);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -2397,7 +2398,7 @@ impl MultiBufferSnapshot {
|
||||
pub fn remote_selections_in_range<'a>(
|
||||
&'a self,
|
||||
range: &'a Range<Anchor>,
|
||||
) -> impl 'a + Iterator<Item = (ReplicaId, Selection<Anchor>)> {
|
||||
) -> impl 'a + Iterator<Item = (ReplicaId, bool, Selection<Anchor>)> {
|
||||
let mut cursor = self.excerpts.cursor::<Option<&ExcerptId>>();
|
||||
cursor.seek(&Some(&range.start.excerpt_id), Bias::Left, &());
|
||||
cursor
|
||||
@@ -2414,7 +2415,7 @@ impl MultiBufferSnapshot {
|
||||
excerpt
|
||||
.buffer
|
||||
.remote_selections_in_range(query_range)
|
||||
.flat_map(move |(replica_id, selections)| {
|
||||
.flat_map(move |(replica_id, line_mode, selections)| {
|
||||
selections.map(move |selection| {
|
||||
let mut start = Anchor {
|
||||
buffer_id: Some(excerpt.buffer_id),
|
||||
@@ -2435,6 +2436,7 @@ impl MultiBufferSnapshot {
|
||||
|
||||
(
|
||||
replica_id,
|
||||
line_mode,
|
||||
Selection {
|
||||
id: selection.id,
|
||||
start,
|
||||
|
||||
@@ -27,6 +27,7 @@ pub struct SelectionsCollection {
|
||||
display_map: ModelHandle<DisplayMap>,
|
||||
buffer: ModelHandle<MultiBuffer>,
|
||||
pub next_selection_id: usize,
|
||||
pub line_mode: bool,
|
||||
disjoint: Arc<[Selection<Anchor>]>,
|
||||
pending: Option<PendingSelection>,
|
||||
}
|
||||
@@ -37,6 +38,7 @@ impl SelectionsCollection {
|
||||
display_map,
|
||||
buffer,
|
||||
next_selection_id: 1,
|
||||
line_mode: true,
|
||||
disjoint: Arc::from([]),
|
||||
pending: Some(PendingSelection {
|
||||
selection: Selection {
|
||||
|
||||
Reference in New Issue
Block a user