Skip to content

Commit cc9fb9d

Browse files
committed
Fix panic caused by focusing the same thing twice
1 parent 5a71188 commit cc9fb9d

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

crates/command_palette2/src/command_palette.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ impl PickerDelegate for CommandPaletteDelegate {
268268
}
269269

270270
fn dismissed(&mut self, cx: &mut ViewContext<Picker<Self>>) {
271-
cx.focus(&self.previous_focus_handle);
272271
self.command_palette
273272
.update(cx, |_, cx| cx.emit(ModalEvent::Dismissed))
274273
.log_err();

crates/gpui2/src/window.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,10 @@ impl<'a> WindowContext<'a> {
407407

408408
/// Move focus to the element associated with the given `FocusHandle`.
409409
pub fn focus(&mut self, handle: &FocusHandle) {
410+
if self.window.focus == Some(handle.id) {
411+
return;
412+
}
413+
410414
if self.window.last_blur.is_none() {
411415
self.window.last_blur = Some(self.window.focus);
412416
}

crates/workspace2/src/modal_layer.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ impl ModalLayer {
3636
let previous_focus = cx.focused();
3737

3838
if let Some(active_modal) = &self.active_modal {
39-
if active_modal.modal.clone().downcast::<V>().is_ok() {
40-
self.hide_modal(cx);
39+
let is_close = active_modal.modal.clone().downcast::<V>().is_ok();
40+
self.hide_modal(cx);
41+
if is_close {
4142
return;
4243
}
4344
}

0 commit comments

Comments
 (0)