Hide selections in original editor when renaming

Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
Nathan Sobo
2022-03-12 10:45:11 -07:00
co-authored by Antonio Scandurra
parent 308cead8a8
commit 992fc07133
2 changed files with 38 additions and 26 deletions
+4 -1
View File
@@ -440,6 +440,7 @@ pub struct Editor {
project: Option<ModelHandle<Project>>, project: Option<ModelHandle<Project>>,
focused: bool, focused: bool,
show_local_cursors: bool, show_local_cursors: bool,
show_local_selections: bool,
blink_epoch: usize, blink_epoch: usize,
blinking_paused: bool, blinking_paused: bool,
mode: EditorMode, mode: EditorMode,
@@ -921,6 +922,7 @@ impl Editor {
autoscroll_request: None, autoscroll_request: None,
focused: false, focused: false,
show_local_cursors: false, show_local_cursors: false,
show_local_selections: true,
blink_epoch: 0, blink_epoch: 0,
blinking_paused: false, blinking_paused: false,
mode, mode,
@@ -4432,6 +4434,7 @@ impl Editor {
drop(buffer); drop(buffer);
// Position the selection in the rename editor so that it matches the current selection. // Position the selection in the rename editor so that it matches the current selection.
this.show_local_selections = false;
let rename_editor = cx.add_view(|cx| { let rename_editor = cx.add_view(|cx| {
let mut editor = Editor::single_line(this.settings.clone(), None, cx); let mut editor = Editor::single_line(this.settings.clone(), None, cx);
if let Some(old_highlight_id) = old_highlight_id { if let Some(old_highlight_id) = old_highlight_id {
@@ -4552,6 +4555,7 @@ impl Editor {
let rename = self.pending_rename.take()?; let rename = self.pending_rename.take()?;
self.remove_blocks([rename.block_id].into_iter().collect(), cx); self.remove_blocks([rename.block_id].into_iter().collect(), cx);
self.clear_text_highlights::<Rename>(cx); self.clear_text_highlights::<Rename>(cx);
self.show_local_selections = true;
if moving_cursor { if moving_cursor {
let cursor_in_rename_editor = let cursor_in_rename_editor =
@@ -5664,7 +5668,6 @@ impl View for Editor {
fn on_blur(&mut self, cx: &mut ViewContext<Self>) { fn on_blur(&mut self, cx: &mut ViewContext<Self>) {
self.focused = false; self.focused = false;
self.show_local_cursors = false;
self.buffer self.buffer
.update(cx, |buffer, cx| buffer.remove_active_selections(cx)); .update(cx, |buffer, cx| buffer.remove_active_selections(cx));
self.hide_context_menu(cx); self.hide_context_menu(cx);
+34 -25
View File
@@ -910,32 +910,37 @@ impl Element for EditorElement {
&display_map, &display_map,
); );
let local_selections = view if view.show_local_selections {
.local_selections_in_range(start_anchor.clone()..end_anchor.clone(), &display_map); let local_selections = view.local_selections_in_range(
for selection in &local_selections { start_anchor.clone()..end_anchor.clone(),
let is_empty = selection.start == selection.end; &display_map,
let selection_start = snapshot.prev_line_boundary(selection.start).1; );
let selection_end = snapshot.next_line_boundary(selection.end).1; for selection in &local_selections {
for row in cmp::max(selection_start.row(), start_row) let is_empty = selection.start == selection.end;
..=cmp::min(selection_end.row(), end_row) let selection_start = snapshot.prev_line_boundary(selection.start).1;
{ let selection_end = snapshot.next_line_boundary(selection.end).1;
let contains_non_empty_selection = active_rows.entry(row).or_insert(!is_empty); for row in cmp::max(selection_start.row(), start_row)
*contains_non_empty_selection |= !is_empty; ..=cmp::min(selection_end.row(), end_row)
{
let contains_non_empty_selection =
active_rows.entry(row).or_insert(!is_empty);
*contains_non_empty_selection |= !is_empty;
}
} }
selections.insert(
view.replica_id(cx),
local_selections
.into_iter()
.map(|selection| crate::Selection {
id: selection.id,
goal: selection.goal,
reversed: selection.reversed,
start: selection.start.to_display_point(&display_map),
end: selection.end.to_display_point(&display_map),
})
.collect(),
);
} }
selections.insert(
view.replica_id(cx),
local_selections
.into_iter()
.map(|selection| crate::Selection {
id: selection.id,
goal: selection.goal,
reversed: selection.reversed,
start: selection.start.to_display_point(&display_map),
end: selection.end.to_display_point(&display_map),
})
.collect(),
);
for (replica_id, selection) in display_map for (replica_id, selection) in display_map
.buffer_snapshot .buffer_snapshot
@@ -1474,7 +1479,11 @@ mod tests {
let (window_id, editor) = cx.add_window(Default::default(), |cx| { let (window_id, editor) = cx.add_window(Default::default(), |cx| {
Editor::new(EditorMode::Full, buffer, None, settings.1, None, cx) Editor::new(EditorMode::Full, buffer, None, settings.1, None, cx)
}); });
let element = EditorElement::new(editor.downgrade(), editor.read(cx).style(cx), CursorShape::Bar); let element = EditorElement::new(
editor.downgrade(),
editor.read(cx).style(cx),
CursorShape::Bar,
);
let layouts = editor.update(cx, |editor, cx| { let layouts = editor.update(cx, |editor, cx| {
let snapshot = editor.snapshot(cx); let snapshot = editor.snapshot(cx);