diff options
author | Pascal Kuthe | 2023-11-30 23:03:26 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2024-01-23 02:20:19 +0000 |
commit | 13ed4f6c4748019787d24c2b686d417b71604242 (patch) | |
tree | 8263b77ee05a22dfc85410345069efb3668b1877 /helix-view/src/document.rs | |
parent | 7d7ace551cd58f0b6d65af7a6dfa8f896d94724a (diff) |
Add hook/event system
Diffstat (limited to 'helix-view/src/document.rs')
-rw-r--r-- | helix-view/src/document.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 6473c2d1..93b83da4 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -36,6 +36,7 @@ use helix_core::{ }; use crate::editor::Config; +use crate::events::{DocumentDidChange, SelectionDidChange}; use crate::{DocumentId, Editor, Theme, View, ViewId}; /// 8kB of buffer space for encoding and decoding `Rope`s. @@ -1096,6 +1097,10 @@ impl Document { // TODO: use a transaction? self.selections .insert(view_id, selection.ensure_invariants(self.text().slice(..))); + helix_event::dispatch(SelectionDidChange { + doc: self, + view: view_id, + }) } /// Find the origin selection of the text in a document, i.e. where @@ -1149,6 +1154,14 @@ impl Document { let success = transaction.changes().apply(&mut self.text); if success { + if emit_lsp_notification { + helix_event::dispatch(DocumentDidChange { + doc: self, + view: view_id, + old_text: &old_doc, + }); + } + for selection in self.selections.values_mut() { *selection = selection .clone() @@ -1164,6 +1177,10 @@ impl Document { view_id, selection.clone().ensure_invariants(self.text.slice(..)), ); + helix_event::dispatch(SelectionDidChange { + doc: self, + view: view_id, + }); } self.modified_since_accessed = true; @@ -1276,6 +1293,7 @@ impl Document { } if emit_lsp_notification { + // TODO: move to hook // emit lsp notification for language_server in self.language_servers() { let notify = language_server.text_document_did_change( |