add DocumentFocusLost event

Pascal Kuthe 4 months ago
parent fef043c652
commit ddb535d3bd
No known key found for this signature in database
GPG Key ID: D715E8655AE166A6

@ -1,6 +1,6 @@
use helix_event::{events, register_event};
use helix_view::document::Mode;
use helix_view::events::{DocumentDidChange, SelectionDidChange};
use helix_view::events::{DocumentDidChange, DocumentFocusLost, SelectionDidChange};
use crate::commands;
use crate::keymap::MappableCommand;
@ -16,5 +16,6 @@ pub fn register() {
register_event::<PostInsertChar>();
register_event::<PostCommand>();
register_event::<DocumentDidChange>();
register_event::<DocumentFocusLost>();
register_event::<SelectionDidChange>();
}

@ -1,6 +1,7 @@
use crate::{
align_view,
document::{DocumentSavedEventFuture, DocumentSavedEventResult, Mode, SavePoint},
events::DocumentFocusLost,
graphics::{CursorKind, Rect},
handlers::Handlers,
info::Info,
@ -12,6 +13,7 @@ use crate::{
Align, Document, DocumentId, View, ViewId,
};
use dap::StackFrame;
use helix_event::dispatch;
use helix_vcs::DiffProviderRegistry;
use futures_util::stream::select_all::SelectAll;
@ -1432,7 +1434,7 @@ impl Editor {
self.enter_normal_mode();
match action {
let focust_lost = match action {
Action::Replace => {
let (view, doc) = current_ref!(self);
// If the current view is an empty scratch buffer and is not displayed in any other views, delete it.
@ -1482,6 +1484,10 @@ impl Editor {
self.replace_document_in_view(view_id, id);
dispatch(DocumentFocusLost {
editor: self,
doc: id,
});
return;
}
Action::Load => {
@ -1492,6 +1498,7 @@ impl Editor {
return;
}
Action::HorizontalSplit | Action::VerticalSplit => {
let focus_lost = self.tree.try_get(self.tree.focus).map(|view| view.doc);
// copy the current view, unless there is no view yet
let view = self
.tree
@ -1511,10 +1518,17 @@ impl Editor {
let doc = doc_mut!(self, &id);
doc.ensure_view_init(view_id);
doc.mark_as_focused();
focus_lost
}
}
};
self._refresh();
if let Some(focus_lost) = focust_lost {
dispatch(DocumentFocusLost {
editor: self,
doc: focus_lost,
});
}
}
/// Generate an id for a new document and register it.
@ -1741,11 +1755,15 @@ impl Editor {
let doc = doc_mut!(self, &view.doc);
view.sync_changes(doc);
}
let view = view!(self, view_id);
let doc = doc_mut!(self, &view.doc);
doc.mark_as_focused();
let focus_lost = self.tree.get(prev_id).doc;
dispatch(DocumentFocusLost {
editor: self,
doc: focus_lost,
});
}
let view = view!(self, view_id);
let doc = doc_mut!(self, &view.doc);
doc.mark_as_focused();
}
pub fn focus_next(&mut self) {

@ -1,7 +1,7 @@
use helix_core::{ChangeSet, Rope};
use helix_event::events;
use crate::{Document, ViewId};
use crate::{Document, DocumentId, Editor, ViewId};
events! {
DocumentDidChange<'a> {
@ -12,4 +12,6 @@ events! {
ghost_transaction: bool
}
SelectionDidChange<'a> { doc: &'a mut Document, view: ViewId }
// called **after** a document loses focus (but not when its closed)
DocumentFocusLost<'a> { editor: &'a mut Editor, doc: DocumentId }
}

Loading…
Cancel
Save