Maintain active selections as editors are focused and blurred

This commit is contained in:
Antonio Scandurra
2021-06-28 12:37:58 +02:00
parent 0bc8663d36
commit e72b4ae03d
3 changed files with 140 additions and 40 deletions
+11 -1
View File
@@ -1991,7 +1991,9 @@ impl Editor {
}
self.buffer.update(cx, |buffer, cx| {
buffer.update_selection_set(self.selection_set_id, selections, cx)
buffer
.update_selection_set(self.selection_set_id, selections, cx)
.unwrap();
});
self.pause_cursor_blinking(cx);
@@ -2432,11 +2434,19 @@ impl View for Editor {
fn on_focus(&mut self, cx: &mut ViewContext<Self>) {
self.focused = true;
self.blink_cursors(self.blink_epoch, cx);
self.buffer.update(cx, |buffer, cx| {
buffer
.set_active_selection_set(Some(self.selection_set_id), cx)
.unwrap();
});
}
fn on_blur(&mut self, cx: &mut ViewContext<Self>) {
self.focused = false;
self.cursors_visible = false;
self.buffer.update(cx, |buffer, cx| {
buffer.set_active_selection_set(None, cx).unwrap();
});
cx.emit(Event::Blurred);
cx.notify();
}