Merge pull request #1764 from zed-industries/gpui-events

Eliminate dispatch_event on Element trait
This commit is contained in:
Nathan Sobo 2022-10-18 15:24:13 -06:00 committed by GitHub
commit f8e5a08324
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
56 changed files with 861 additions and 1245 deletions

View file

@ -48,7 +48,9 @@ use language::{
Diagnostic, DiagnosticSeverity, IndentKind, IndentSize, Language, OffsetRangeExt, OffsetUtf16,
Point, Selection, SelectionGoal, TransactionId,
};
use link_go_to_definition::{hide_link_definition, LinkGoToDefinitionState};
use link_go_to_definition::{
hide_link_definition, show_link_definition, LinkDefinitionKind, LinkGoToDefinitionState,
};
pub use multi_buffer::{
Anchor, AnchorRangeExt, ExcerptId, ExcerptRange, MultiBuffer, MultiBufferSnapshot, ToOffset,
ToPoint,
@ -6425,7 +6427,7 @@ impl View for Editor {
"Editor"
}
fn on_focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
let focused_event = EditorFocused(cx.handle());
cx.emit_global(focused_event);
if let Some(rename) = self.pending_rename.as_ref() {
@ -6447,7 +6449,7 @@ impl View for Editor {
}
}
fn on_focus_out(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
fn focus_out(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
let blurred_event = EditorBlurred(cx.handle());
cx.emit_global(blurred_event);
self.focused = false;
@ -6460,6 +6462,44 @@ impl View for Editor {
cx.notify();
}
fn modifiers_changed(
&mut self,
event: &gpui::ModifiersChangedEvent,
cx: &mut ViewContext<Self>,
) -> bool {
let pending_selection = self.has_pending_selection();
if let Some(point) = self.link_go_to_definition_state.last_mouse_location.clone() {
if event.cmd && !pending_selection {
let snapshot = self.snapshot(cx);
let kind = if event.shift {
LinkDefinitionKind::Type
} else {
LinkDefinitionKind::Symbol
};
show_link_definition(kind, self, point, snapshot, cx);
return false;
}
}
{
if self.link_go_to_definition_state.symbol_range.is_some()
|| !self.link_go_to_definition_state.definitions.is_empty()
{
self.link_go_to_definition_state.symbol_range.take();
self.link_go_to_definition_state.definitions.clear();
cx.notify();
}
self.link_go_to_definition_state.task = None;
self.clear_text_highlights::<LinkGoToDefinitionState>(cx);
}
false
}
fn keymap_context(&self, _: &AppContext) -> gpui::keymap::Context {
let mut context = Self::default_keymap_context();
let mode = match self.mode {