Fix panic caused by focusing the same thing twice
This commit is contained in:
parent
5a711886d4
commit
cc9fb9dea0
3 changed files with 7 additions and 3 deletions
|
@ -268,7 +268,6 @@ impl PickerDelegate for CommandPaletteDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dismissed(&mut self, cx: &mut ViewContext<Picker<Self>>) {
|
fn dismissed(&mut self, cx: &mut ViewContext<Picker<Self>>) {
|
||||||
cx.focus(&self.previous_focus_handle);
|
|
||||||
self.command_palette
|
self.command_palette
|
||||||
.update(cx, |_, cx| cx.emit(ModalEvent::Dismissed))
|
.update(cx, |_, cx| cx.emit(ModalEvent::Dismissed))
|
||||||
.log_err();
|
.log_err();
|
||||||
|
|
|
@ -407,6 +407,10 @@ impl<'a> WindowContext<'a> {
|
||||||
|
|
||||||
/// Move focus to the element associated with the given `FocusHandle`.
|
/// Move focus to the element associated with the given `FocusHandle`.
|
||||||
pub fn focus(&mut self, handle: &FocusHandle) {
|
pub fn focus(&mut self, handle: &FocusHandle) {
|
||||||
|
if self.window.focus == Some(handle.id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if self.window.last_blur.is_none() {
|
if self.window.last_blur.is_none() {
|
||||||
self.window.last_blur = Some(self.window.focus);
|
self.window.last_blur = Some(self.window.focus);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,8 +36,9 @@ impl ModalLayer {
|
||||||
let previous_focus = cx.focused();
|
let previous_focus = cx.focused();
|
||||||
|
|
||||||
if let Some(active_modal) = &self.active_modal {
|
if let Some(active_modal) = &self.active_modal {
|
||||||
if active_modal.modal.clone().downcast::<V>().is_ok() {
|
let is_close = active_modal.modal.clone().downcast::<V>().is_ok();
|
||||||
self.hide_modal(cx);
|
self.hide_modal(cx);
|
||||||
|
if is_close {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue