Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-view/src/document.rs')
-rw-r--r--helix-view/src/document.rs50
1 files changed, 33 insertions, 17 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index e52dbe0f..c0672001 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -204,14 +204,11 @@ pub struct Document {
pub readonly: bool,
- pub previous_diagnostic_id: Option<String>,
-
/// Annotations for LSP document color swatches
pub color_swatches: Option<DocumentColorSwatches>,
// NOTE: ideally this would live on the handler for color swatches. This is blocked on a
// large refactor that would make `&mut Editor` available on the `DocumentDidChange` event.
pub color_swatch_controller: TaskController,
- pub pull_diagnostic_controller: TaskController,
// NOTE: this field should eventually go away - we should use the Editor's syn_loader instead
// of storing a copy on every doc. Then we can remove the surrounding `Arc` and use the
@@ -731,8 +728,6 @@ impl Document {
color_swatches: None,
color_swatch_controller: TaskController::new(),
syn_loader,
- previous_diagnostic_id: None,
- pull_diagnostic_controller: TaskController::new(),
}
}
@@ -980,7 +975,7 @@ impl Document {
};
let identifier = self.path().map(|_| self.identifier());
- let language_servers: Vec<_> = self.language_servers.values().cloned().collect();
+ let language_servers = self.language_servers.clone();
// mark changes up to now as saved
let current_rev = self.get_current_revision();
@@ -1124,7 +1119,7 @@ impl Document {
text: text.clone(),
};
- for language_server in language_servers {
+ for (_, language_server) in language_servers {
if !language_server.is_initialized() {
continue;
}
@@ -1325,15 +1320,27 @@ impl Document {
Ok(())
}
- /// Select text within the [`Document`].
- pub fn set_selection(&mut self, view_id: ViewId, selection: Selection) {
+ /// Select text within the [`Document`], optionally clearing the previous selection state.
+ pub fn set_selection_clear(&mut self, view_id: ViewId, selection: Selection, clear_prev: bool) {
// TODO: use a transaction?
self.selections
.insert(view_id, selection.ensure_invariants(self.text().slice(..)));
+
helix_event::dispatch(SelectionDidChange {
doc: self,
view: view_id,
- })
+ });
+
+ if clear_prev {
+ self.view_data
+ .entry(view_id)
+ .and_modify(|view_data| view_data.object_selections.clear());
+ }
+ }
+
+ /// Select text within the [`Document`].
+ pub fn set_selection(&mut self, view_id: ViewId, selection: Selection) {
+ self.set_selection_clear(view_id, selection, true);
}
/// Find the origin selection of the text in a document, i.e. where
@@ -1525,6 +1532,12 @@ impl Document {
apply_inlay_hint_changes(padding_after_inlay_hints);
}
+ // clear out all associated view object selections, as they are no
+ // longer valid
+ self.view_data
+ .values_mut()
+ .for_each(|view_data| view_data.object_selections.clear());
+
helix_event::dispatch(DocumentDidChange {
doc: self,
view: view_id,
@@ -1660,7 +1673,7 @@ impl Document {
let savepoint_idx = self
.savepoints
.iter()
- .position(|savepoint_ref| std::ptr::eq(savepoint_ref.as_ptr(), savepoint))
+ .position(|savepoint_ref| savepoint_ref.as_ptr() == savepoint as *const _)
.expect("Savepoint must belong to this document");
let savepoint_ref = self.savepoints.remove(savepoint_idx);
@@ -1967,13 +1980,13 @@ impl Document {
&self.selections
}
- fn view_data(&self, view_id: ViewId) -> &ViewData {
+ pub fn view_data(&self, view_id: ViewId) -> &ViewData {
self.view_data
.get(&view_id)
.expect("This should only be called after ensure_view_init")
}
- fn view_data_mut(&mut self, view_id: ViewId) -> &mut ViewData {
+ pub fn view_data_mut(&mut self, view_id: ViewId) -> &mut ViewData {
self.view_data.entry(view_id).or_default()
}
@@ -2289,15 +2302,15 @@ impl Document {
pub fn reset_all_inlay_hints(&mut self) {
self.inlay_hints = Default::default();
}
-
- pub fn has_language_server_with_feature(&self, feature: LanguageServerFeature) -> bool {
- self.language_servers_with_feature(feature).next().is_some()
- }
}
+/// Stores data needed for views that are tied to this specific Document.
#[derive(Debug, Default)]
pub struct ViewData {
view_position: ViewPosition,
+
+ /// used to store previous selections of tree-sitter objects
+ pub object_selections: HashMap<&'static str, Vec<Selection>>,
}
#[derive(Clone, Debug)]
@@ -2348,6 +2361,7 @@ mod test {
Arc::new(ArcSwap::from_pointee(syntax::Loader::default())),
);
let view = ViewId::default();
+ doc.ensure_view_init(view);
doc.set_selection(view, Selection::single(0, 0));
let transaction =
@@ -2386,7 +2400,9 @@ mod test {
Arc::new(ArcSwap::new(Arc::new(Config::default()))),
Arc::new(ArcSwap::from_pointee(syntax::Loader::default())),
);
+
let view = ViewId::default();
+ doc.ensure_view_init(view);
doc.set_selection(view, Selection::single(5, 5));
// insert