mirror of https://github.com/helix-editor/helix
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
parent
2338b44909
commit
43963473e3
|
@ -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;
|
||||
|
|
|
@ -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::<DiagnosticsDidChange>();
|
||||
register_event::<LanguageServerInitialized>();
|
||||
register_event::<LanguageServerExited>();
|
||||
register_event::<ConfigDidChange>();
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue