Add Editor::remove_blocks

Max Brunsfeld created

Change summary

crates/editor/src/display_map.rs           |  6 ++----
crates/editor/src/display_map/block_map.rs |  2 +-
crates/editor/src/editor.rs                | 14 ++++++++++----
crates/editor/src/element.rs               |  8 +++-----
4 files changed, 16 insertions(+), 14 deletions(-)

Detailed changes

crates/editor/src/display_map.rs 🔗

@@ -5,13 +5,11 @@ mod wrap_map;
 
 use crate::{Anchor, MultiBuffer, MultiBufferSnapshot, ToOffset, ToPoint};
 use block_map::{BlockMap, BlockPoint};
+use collections::{HashMap, HashSet};
 use fold_map::{FoldMap, ToFoldPoint as _};
 use gpui::{fonts::FontId, Entity, ModelContext, ModelHandle};
 use language::{Point, Subscription as BufferSubscription};
-use std::{
-    collections::{HashMap, HashSet},
-    ops::Range,
-};
+use std::ops::Range;
 use sum_tree::Bias;
 use tab_map::TabMap;
 use theme::SyntaxTheme;

crates/editor/src/display_map/block_map.rs 🔗

@@ -1,11 +1,11 @@
 use super::wrap_map::{self, WrapEdit, WrapPoint, WrapSnapshot};
 use crate::{Anchor, ToOffset, ToPoint as _};
+use collections::{HashMap, HashSet};
 use gpui::{AppContext, ElementBox};
 use language::Chunk;
 use parking_lot::Mutex;
 use std::{
     cmp::{self, Ordering},
-    collections::{HashMap, HashSet},
     fmt::Debug,
     ops::{Deref, Range},
     sync::{

crates/editor/src/editor.rs 🔗

@@ -9,6 +9,7 @@ mod test;
 
 use aho_corasick::AhoCorasick;
 use clock::ReplicaId;
+use collections::{HashMap, HashSet};
 pub use display_map::DisplayPoint;
 use display_map::*;
 pub use element::*;
@@ -27,7 +28,7 @@ use language::{
     BracketPair, Buffer, Diagnostic, DiagnosticSeverity, Language, Point, Selection, SelectionGoal,
     TransactionId,
 };
-pub use multi_buffer::{Anchor, ExcerptProperties, MultiBuffer};
+pub use multi_buffer::{Anchor, ExcerptId, ExcerptProperties, MultiBuffer};
 use multi_buffer::{AnchorRangeExt, MultiBufferChunks, MultiBufferSnapshot, ToOffset, ToPoint};
 use postage::watch;
 use serde::{Deserialize, Serialize};
@@ -35,7 +36,6 @@ use smallvec::SmallVec;
 use smol::Timer;
 use std::{
     cmp,
-    collections::HashMap,
     iter::{self, FromIterator},
     mem,
     ops::{Deref, Range, RangeInclusive, Sub},
@@ -2893,7 +2893,7 @@ impl Editor {
 
             if is_valid != active_diagnostics.is_valid {
                 active_diagnostics.is_valid = is_valid;
-                let mut new_styles = HashMap::new();
+                let mut new_styles = HashMap::default();
                 for (block_id, diagnostic) in &active_diagnostics.blocks {
                     new_styles.insert(
                         *block_id,
@@ -3051,7 +3051,7 @@ impl Editor {
             }
         }
 
-        let mut result = HashMap::new();
+        let mut result = HashMap::default();
 
         result.insert(
             self.replica_id(cx),
@@ -3423,6 +3423,12 @@ impl Editor {
         }
     }
 
+    pub fn remove_blocks(&mut self, block_ids: HashSet<BlockId>, cx: &mut ViewContext<Self>) {
+        self.display_map.update(cx, |display_map, cx| {
+            display_map.remove_blocks(block_ids, cx)
+        });
+    }
+
     pub fn insert_blocks<P>(
         &mut self,
         blocks: impl IntoIterator<Item = BlockProperties<P>>,

crates/editor/src/element.rs 🔗

@@ -1,11 +1,10 @@
-use crate::display_map::{BlockContext, ToDisplayPoint};
-
 use super::{
+    display_map::{BlockContext, ToDisplayPoint},
     DisplayPoint, Editor, EditorMode, EditorSettings, EditorSnapshot, EditorStyle, Input, Scroll,
-    Select, SelectPhase, SoftWrap, MAX_LINE_LEN,
+    Select, SelectPhase, SoftWrap, ToPoint, MAX_LINE_LEN,
 };
-use crate::ToPoint;
 use clock::ReplicaId;
+use collections::{BTreeMap, HashMap};
 use gpui::{
     color::Color,
     geometry::{
@@ -24,7 +23,6 @@ use language::Chunk;
 use smallvec::SmallVec;
 use std::{
     cmp::{self, Ordering},
-    collections::{BTreeMap, HashMap},
     fmt::Write,
     ops::Range,
 };