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).
pull/13827/head
Michael Davis 2025-06-23 10:48:57 -04:00
parent 2338b44909
commit 43963473e3
No known key found for this signature in database
4 changed files with 21 additions and 5 deletions

View File

@ -356,6 +356,8 @@ impl Application {
} }
pub fn handle_config_events(&mut self, config_event: ConfigEvent) { pub fn handle_config_events(&mut self, config_event: ConfigEvent) {
let old_editor_config = self.editor.config();
match config_event { match config_event {
ConfigEvent::Refresh => self.refresh_config(), ConfigEvent::Refresh => self.refresh_config(),
@ -374,7 +376,7 @@ impl Application {
// Update all the relevant members in the editor after updating // Update all the relevant members in the editor after updating
// the configuration. // the configuration.
self.editor.refresh_config(); self.editor.refresh_config(&old_editor_config);
// reset view position in case softwrap was enabled/disabled // reset view position in case softwrap was enabled/disabled
let scrolloff = self.editor.config().scrolloff; let scrolloff = self.editor.config().scrolloff;

View File

@ -1,8 +1,8 @@
use helix_event::{events, register_event}; use helix_event::{events, register_event};
use helix_view::document::Mode; use helix_view::document::Mode;
use helix_view::events::{ use helix_view::events::{
DiagnosticsDidChange, DocumentDidChange, DocumentDidClose, DocumentDidOpen, DocumentFocusLost, ConfigDidChange, DiagnosticsDidChange, DocumentDidChange, DocumentDidClose, DocumentDidOpen,
LanguageServerExited, LanguageServerInitialized, SelectionDidChange, DocumentFocusLost, LanguageServerExited, LanguageServerInitialized, SelectionDidChange,
}; };
use crate::commands; use crate::commands;
@ -26,4 +26,5 @@ pub fn register() {
register_event::<DiagnosticsDidChange>(); register_event::<DiagnosticsDidChange>();
register_event::<LanguageServerInitialized>(); register_event::<LanguageServerInitialized>();
register_event::<LanguageServerExited>(); register_event::<LanguageServerExited>();
register_event::<ConfigDidChange>();
} }

View File

@ -1289,11 +1289,16 @@ impl Editor {
/// Call if the config has changed to let the editor update all /// Call if the config has changed to let the editor update all
/// relevant members. /// relevant members.
pub fn refresh_config(&mut self) { pub fn refresh_config(&mut self, old_config: &Config) {
let config = self.config(); let config = self.config();
self.auto_pairs = (&config.auto_pairs).into(); self.auto_pairs = (&config.auto_pairs).into();
self.reset_idle_timer(); self.reset_idle_timer();
self._refresh(); self._refresh();
helix_event::dispatch(crate::events::ConfigDidChange {
editor: self,
old: old_config,
new: &config,
})
} }
pub fn clear_idle_timer(&mut self) { pub fn clear_idle_timer(&mut self) {

View File

@ -2,7 +2,7 @@ use helix_core::{ChangeSet, Rope};
use helix_event::events; use helix_event::events;
use helix_lsp::LanguageServerId; use helix_lsp::LanguageServerId;
use crate::{Document, DocumentId, Editor, ViewId}; use crate::{editor::Config, Document, DocumentId, Editor, ViewId};
events! { events! {
DocumentDidOpen<'a> { DocumentDidOpen<'a> {
@ -33,4 +33,12 @@ events! {
editor: &'a mut Editor, editor: &'a mut Editor,
server_id: LanguageServerId 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
}
} }