terminal_view: Fix terminal stealing focus on editor selection (#31639)

Closes #28234

Release Notes:

- Fixed the issue where the terminal focused when the mouse hovered over
it after selecting text in the editor.
This commit is contained in:
Smit Barmase 2025-05-29 08:55:12 +05:30 committed by GitHub
parent f9407db7d6
commit 87f097a0ab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -413,10 +413,15 @@ impl TerminalElement {
fn generic_button_handler<E>( fn generic_button_handler<E>(
connection: Entity<Terminal>, connection: Entity<Terminal>,
focus_handle: FocusHandle, focus_handle: FocusHandle,
steal_focus: bool,
f: impl Fn(&mut Terminal, &E, &mut Context<Terminal>), f: impl Fn(&mut Terminal, &E, &mut Context<Terminal>),
) -> impl Fn(&E, &mut Window, &mut App) { ) -> impl Fn(&E, &mut Window, &mut App) {
move |event, window, cx| { move |event, window, cx| {
window.focus(&focus_handle); if steal_focus {
window.focus(&focus_handle);
} else if !focus_handle.is_focused(window) {
return;
}
connection.update(cx, |terminal, cx| { connection.update(cx, |terminal, cx| {
f(terminal, event, cx); f(terminal, event, cx);
@ -489,6 +494,7 @@ impl TerminalElement {
TerminalElement::generic_button_handler( TerminalElement::generic_button_handler(
terminal.clone(), terminal.clone(),
focus.clone(), focus.clone(),
false,
move |terminal, e, cx| { move |terminal, e, cx| {
terminal.mouse_up(e, cx); terminal.mouse_up(e, cx);
}, },
@ -499,6 +505,7 @@ impl TerminalElement {
TerminalElement::generic_button_handler( TerminalElement::generic_button_handler(
terminal.clone(), terminal.clone(),
focus.clone(), focus.clone(),
true,
move |terminal, e, cx| { move |terminal, e, cx| {
terminal.mouse_down(e, cx); terminal.mouse_down(e, cx);
}, },
@ -528,6 +535,7 @@ impl TerminalElement {
TerminalElement::generic_button_handler( TerminalElement::generic_button_handler(
terminal.clone(), terminal.clone(),
focus.clone(), focus.clone(),
true,
move |terminal, e, cx| { move |terminal, e, cx| {
terminal.mouse_down(e, cx); terminal.mouse_down(e, cx);
}, },
@ -538,6 +546,7 @@ impl TerminalElement {
TerminalElement::generic_button_handler( TerminalElement::generic_button_handler(
terminal.clone(), terminal.clone(),
focus.clone(), focus.clone(),
false,
move |terminal, e, cx| { move |terminal, e, cx| {
terminal.mouse_up(e, cx); terminal.mouse_up(e, cx);
}, },
@ -545,9 +554,14 @@ impl TerminalElement {
); );
self.interactivity.on_mouse_up( self.interactivity.on_mouse_up(
MouseButton::Middle, MouseButton::Middle,
TerminalElement::generic_button_handler(terminal, focus, move |terminal, e, cx| { TerminalElement::generic_button_handler(
terminal.mouse_up(e, cx); terminal,
}), focus,
false,
move |terminal, e, cx| {
terminal.mouse_up(e, cx);
},
),
); );
} }
} }