Skip to content

Commit 4396347

Browse files
committed
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).
1 parent 2338b44 commit 4396347

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

helix-term/src/application.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ impl Application {
356356
}
357357

358358
pub fn handle_config_events(&mut self, config_event: ConfigEvent) {
359+
let old_editor_config = self.editor.config();
360+
359361
match config_event {
360362
ConfigEvent::Refresh => self.refresh_config(),
361363

@@ -374,7 +376,7 @@ impl Application {
374376

375377
// Update all the relevant members in the editor after updating
376378
// the configuration.
377-
self.editor.refresh_config();
379+
self.editor.refresh_config(&old_editor_config);
378380

379381
// reset view position in case softwrap was enabled/disabled
380382
let scrolloff = self.editor.config().scrolloff;

helix-term/src/events.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use helix_event::{events, register_event};
22
use helix_view::document::Mode;
33
use helix_view::events::{
4-
DiagnosticsDidChange, DocumentDidChange, DocumentDidClose, DocumentDidOpen, DocumentFocusLost,
5-
LanguageServerExited, LanguageServerInitialized, SelectionDidChange,
4+
ConfigDidChange, DiagnosticsDidChange, DocumentDidChange, DocumentDidClose, DocumentDidOpen,
5+
DocumentFocusLost, LanguageServerExited, LanguageServerInitialized, SelectionDidChange,
66
};
77

88
use crate::commands;
@@ -26,4 +26,5 @@ pub fn register() {
2626
register_event::<DiagnosticsDidChange>();
2727
register_event::<LanguageServerInitialized>();
2828
register_event::<LanguageServerExited>();
29+
register_event::<ConfigDidChange>();
2930
}

helix-view/src/editor.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1289,11 +1289,16 @@ impl Editor {
12891289

12901290
/// Call if the config has changed to let the editor update all
12911291
/// relevant members.
1292-
pub fn refresh_config(&mut self) {
1292+
pub fn refresh_config(&mut self, old_config: &Config) {
12931293
let config = self.config();
12941294
self.auto_pairs = (&config.auto_pairs).into();
12951295
self.reset_idle_timer();
12961296
self._refresh();
1297+
helix_event::dispatch(crate::events::ConfigDidChange {
1298+
editor: self,
1299+
old: old_config,
1300+
new: &config,
1301+
})
12971302
}
12981303

12991304
pub fn clear_idle_timer(&mut self) {

helix-view/src/events.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use helix_core::{ChangeSet, Rope};
22
use helix_event::events;
33
use helix_lsp::LanguageServerId;
44

5-
use crate::{Document, DocumentId, Editor, ViewId};
5+
use crate::{editor::Config, Document, DocumentId, Editor, ViewId};
66

77
events! {
88
DocumentDidOpen<'a> {
@@ -33,4 +33,12 @@ events! {
3333
editor: &'a mut Editor,
3434
server_id: LanguageServerId
3535
}
36+
37+
// NOTE: this event is simple for now and is expected to change as the config system evolves.
38+
// Ideally it would say what changed.
39+
ConfigDidChange<'a> {
40+
editor: &'a mut Editor,
41+
old: &'a Config,
42+
new: &'a Config
43+
}
3644
}

0 commit comments

Comments
 (0)