Don't hide inline assist when editor loses focus (#12990)
Release Notes: - Now when an editor loses focus (e.g. from switching tabs) and then gains focus again, it doesn't close the inline assist. Instead, it only closes when you move the cursor outside of it, e.g. by clicking somewhere else in its parent editor. --------- Co-authored-by: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
parent
15d3e54ae3
commit
4855da53df
9 changed files with 90 additions and 81 deletions
|
@ -66,11 +66,12 @@ use git::diff_hunk_to_display;
|
|||
use gpui::{
|
||||
div, impl_actions, point, prelude::*, px, relative, size, uniform_list, Action, AnyElement,
|
||||
AppContext, AsyncWindowContext, AvailableSpace, BackgroundExecutor, Bounds, ClipboardItem,
|
||||
Context, DispatchPhase, ElementId, EventEmitter, FocusHandle, FocusableView, FontId, FontStyle,
|
||||
FontWeight, HighlightStyle, Hsla, InteractiveText, KeyContext, ListSizingBehavior, Model,
|
||||
MouseButton, PaintQuad, ParentElement, Pixels, Render, SharedString, Size, StrikethroughStyle,
|
||||
Styled, StyledText, Subscription, Task, TextStyle, UnderlineStyle, UniformListScrollHandle,
|
||||
View, ViewContext, ViewInputHandler, VisualContext, WeakView, WhiteSpace, WindowContext,
|
||||
Context, DispatchPhase, ElementId, EventEmitter, FocusHandle, FocusOutEvent, FocusableView,
|
||||
FontId, FontStyle, FontWeight, HighlightStyle, Hsla, InteractiveText, KeyContext,
|
||||
ListSizingBehavior, Model, MouseButton, PaintQuad, ParentElement, Pixels, Render, SharedString,
|
||||
Size, StrikethroughStyle, Styled, StyledText, Subscription, Task, TextStyle, UnderlineStyle,
|
||||
UniformListScrollHandle, View, ViewContext, ViewInputHandler, VisualContext, WeakFocusHandle,
|
||||
WeakView, WhiteSpace, WindowContext,
|
||||
};
|
||||
use highlight_matching_bracket::refresh_matching_bracket_highlights;
|
||||
use hover_popover::{hide_hover, HoverState};
|
||||
|
@ -448,6 +449,7 @@ struct BufferOffset(usize);
|
|||
/// See the [module level documentation](self) for more information.
|
||||
pub struct Editor {
|
||||
focus_handle: FocusHandle,
|
||||
last_focused: Option<WeakFocusHandle>,
|
||||
/// The text buffer being edited
|
||||
buffer: Model<MultiBuffer>,
|
||||
/// Map of how text in the buffer should be displayed.
|
||||
|
@ -1735,6 +1737,8 @@ impl Editor {
|
|||
);
|
||||
let focus_handle = cx.focus_handle();
|
||||
cx.on_focus(&focus_handle, Self::handle_focus).detach();
|
||||
cx.on_focus_out(&focus_handle, Self::handle_focus_out)
|
||||
.detach();
|
||||
cx.on_blur(&focus_handle, Self::handle_blur).detach();
|
||||
|
||||
let show_indent_guides = if mode == EditorMode::SingleLine {
|
||||
|
@ -1745,6 +1749,7 @@ impl Editor {
|
|||
|
||||
let mut this = Self {
|
||||
focus_handle,
|
||||
last_focused: None,
|
||||
buffer: buffer.clone(),
|
||||
display_map: display_map.clone(),
|
||||
selections,
|
||||
|
@ -11315,9 +11320,13 @@ impl Editor {
|
|||
|
||||
fn handle_focus(&mut self, cx: &mut ViewContext<Self>) {
|
||||
cx.emit(EditorEvent::Focused);
|
||||
if let Some(rename) = self.pending_rename.as_ref() {
|
||||
let rename_editor_focus_handle = rename.editor.read(cx).focus_handle.clone();
|
||||
cx.focus(&rename_editor_focus_handle);
|
||||
|
||||
if let Some(last_focused) = self
|
||||
.last_focused
|
||||
.take()
|
||||
.and_then(|last_focused| last_focused.upgrade())
|
||||
{
|
||||
cx.focus(&last_focused);
|
||||
} else {
|
||||
if let Some(blame) = self.blame.as_ref() {
|
||||
blame.update(cx, GitBlame::focus)
|
||||
|
@ -11339,6 +11348,10 @@ impl Editor {
|
|||
}
|
||||
}
|
||||
|
||||
fn handle_focus_out(&mut self, event: FocusOutEvent, _cx: &mut ViewContext<Self>) {
|
||||
self.last_focused = Some(event.blurred);
|
||||
}
|
||||
|
||||
pub fn handle_blur(&mut self, cx: &mut ViewContext<Self>) {
|
||||
self.blink_manager.update(cx, BlinkManager::disable);
|
||||
self.buffer
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue