Skip to content

Commit 07c69c1

Browse files
committed
fix: update blame when editing config
1 parent 647615d commit 07c69c1

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

helix-term/src/application.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use helix_view::{
1111
align_view,
1212
document::{DocumentOpenError, DocumentSavedEventResult},
1313
editor::{ConfigEvent, EditorEvent},
14+
events::EditorConfigDidChange,
1415
graphics::Rect,
1516
theme,
1617
tree::Layout,
@@ -364,6 +365,11 @@ impl Application {
364365
// the Application can apply it.
365366
ConfigEvent::Update(editor_config) => {
366367
let mut app_config = (*self.config.load().clone()).clone();
368+
helix_event::dispatch(EditorConfigDidChange {
369+
old_config: &app_config.editor,
370+
new_config: &editor_config,
371+
editor: &mut self.editor,
372+
});
367373
app_config.editor = *editor_config;
368374
if let Err(err) = self.terminal.reconfigure(app_config.editor.clone().into()) {
369375
self.editor.set_error(err.to_string());

helix-term/src/events.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use helix_event::{events, register_event};
22
use helix_view::document::Mode;
33
use helix_view::events::{
44
DiagnosticsDidChange, DocumentDidChange, DocumentDidClose, DocumentDidOpen, DocumentFocusLost,
5-
LanguageServerExited, LanguageServerInitialized, SelectionDidChange,
5+
EditorConfigDidChange, LanguageServerExited, LanguageServerInitialized, SelectionDidChange,
66
};
77

88
use crate::commands;
@@ -20,6 +20,7 @@ pub fn register() {
2020
register_event::<PostCommand>();
2121
register_event::<DocumentDidOpen>();
2222
register_event::<DocumentDidChange>();
23+
register_event::<EditorConfigDidChange>();
2324
register_event::<DocumentDidClose>();
2425
register_event::<DocumentFocusLost>();
2526
register_event::<SelectionDidChange>();

helix-term/src/handlers/blame.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use helix_event::register_hook;
44
use helix_vcs::FileBlame;
55
use helix_view::{
66
editor::InlineBlameBehaviour,
7-
events::DocumentDidOpen,
7+
events::{DocumentDidOpen, EditorConfigDidChange},
88
handlers::{BlameEvent, Handlers},
99
DocumentId,
1010
};
@@ -91,4 +91,26 @@ pub(super) fn register_hooks(handlers: &Handlers) {
9191
}
9292
Ok(())
9393
});
94+
let tx = handlers.blame.clone();
95+
register_hook!(move |event: &mut EditorConfigDidChange<'_>| {
96+
if event.old_config.inline_blame.behaviour == InlineBlameBehaviour::Disabled
97+
&& event.new_config.inline_blame.behaviour != InlineBlameBehaviour::Disabled
98+
{
99+
// request blame for all documents, since any of them could have
100+
// outdated blame
101+
for doc in event.editor.documents() {
102+
if let Some(path) = doc.path() {
103+
helix_event::send_blocking(
104+
&tx,
105+
BlameEvent {
106+
path: path.to_path_buf(),
107+
doc_id: doc.id(),
108+
line: None,
109+
},
110+
);
111+
}
112+
}
113+
}
114+
Ok(())
115+
});
94116
}

helix-view/src/events.rs

Lines changed: 6 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> {
@@ -17,6 +17,11 @@ events! {
1717
changes: &'a ChangeSet,
1818
ghost_transaction: bool
1919
}
20+
EditorConfigDidChange<'a> {
21+
old_config: &'a Config,
22+
new_config: &'a Config,
23+
editor: &'a mut Editor
24+
}
2025
DocumentDidClose<'a> {
2126
editor: &'a mut Editor,
2227
doc: Document

0 commit comments

Comments
 (0)