From 43963473e372b18c94b725a1baa53b0175c86a86 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Mon, 23 Jun 2025 10:48:57 -0400 Subject: [PATCH] Add a `ConfigDidChange` event This is meant to be minimal for now and is expected to change as the config system evolves. Features like word completion should be able to hook into this to initialize or clear the word index when the toggle for the feature is turned on or off (respectively). --- helix-term/src/application.rs | 4 +++- helix-term/src/events.rs | 5 +++-- helix-view/src/editor.rs | 7 ++++++- helix-view/src/events.rs | 10 +++++++++- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index dd19a2d72..17b58420c 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -356,6 +356,8 @@ impl Application { } pub fn handle_config_events(&mut self, config_event: ConfigEvent) { + let old_editor_config = self.editor.config(); + match config_event { ConfigEvent::Refresh => self.refresh_config(), @@ -374,7 +376,7 @@ impl Application { // Update all the relevant members in the editor after updating // the configuration. - self.editor.refresh_config(); + self.editor.refresh_config(&old_editor_config); // reset view position in case softwrap was enabled/disabled let scrolloff = self.editor.config().scrolloff; diff --git a/helix-term/src/events.rs b/helix-term/src/events.rs index 80f045cd7..b0a422989 100644 --- a/helix-term/src/events.rs +++ b/helix-term/src/events.rs @@ -1,8 +1,8 @@ use helix_event::{events, register_event}; use helix_view::document::Mode; use helix_view::events::{ - DiagnosticsDidChange, DocumentDidChange, DocumentDidClose, DocumentDidOpen, DocumentFocusLost, - LanguageServerExited, LanguageServerInitialized, SelectionDidChange, + ConfigDidChange, DiagnosticsDidChange, DocumentDidChange, DocumentDidClose, DocumentDidOpen, + DocumentFocusLost, LanguageServerExited, LanguageServerInitialized, SelectionDidChange, }; use crate::commands; @@ -26,4 +26,5 @@ pub fn register() { register_event::(); register_event::(); register_event::(); + register_event::(); } diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 575a0b5f1..2e5c60cfa 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -1289,11 +1289,16 @@ impl Editor { /// Call if the config has changed to let the editor update all /// relevant members. - pub fn refresh_config(&mut self) { + pub fn refresh_config(&mut self, old_config: &Config) { let config = self.config(); self.auto_pairs = (&config.auto_pairs).into(); self.reset_idle_timer(); self._refresh(); + helix_event::dispatch(crate::events::ConfigDidChange { + editor: self, + old: old_config, + new: &config, + }) } pub fn clear_idle_timer(&mut self) { diff --git a/helix-view/src/events.rs b/helix-view/src/events.rs index 4a44beb35..0435e6a47 100644 --- a/helix-view/src/events.rs +++ b/helix-view/src/events.rs @@ -2,7 +2,7 @@ use helix_core::{ChangeSet, Rope}; use helix_event::events; use helix_lsp::LanguageServerId; -use crate::{Document, DocumentId, Editor, ViewId}; +use crate::{editor::Config, Document, DocumentId, Editor, ViewId}; events! { DocumentDidOpen<'a> { @@ -33,4 +33,12 @@ events! { editor: &'a mut Editor, server_id: LanguageServerId } + + // NOTE: this event is simple for now and is expected to change as the config system evolves. + // Ideally it would say what changed. + ConfigDidChange<'a> { + editor: &'a mut Editor, + old: &'a Config, + new: &'a Config + } }