Fix divide by 0 in terminal

Fix fail to remove contact in contact list
This commit is contained in:
Mikayla Maki 2023-03-16 12:31:50 -07:00
parent 1fbdea6a03
commit c3325430ca
2 changed files with 13 additions and 2 deletions

View file

@ -316,12 +316,20 @@ impl ContactList {
github_login github_login
); );
let mut answer = cx.prompt(PromptLevel::Warning, &prompt_message, &["Remove", "Cancel"]); let mut answer = cx.prompt(PromptLevel::Warning, &prompt_message, &["Remove", "Cancel"]);
let window_id = cx.window_id();
cx.spawn(|_, mut cx| async move { cx.spawn(|_, mut cx| async move {
if answer.next().await == Some(0) { if answer.next().await == Some(0) {
user_store if let Err(e) = user_store
.update(&mut cx, |store, cx| store.remove_contact(user_id, cx)) .update(&mut cx, |store, cx| store.remove_contact(user_id, cx))
.await .await
.unwrap(); {
cx.prompt(
window_id,
PromptLevel::Info,
&format!("Failed to remove contact: {}", e),
&["Ok"],
);
}
} }
}) })
.detach(); .detach();

View file

@ -186,6 +186,9 @@ pub fn mouse_moved_report(point: Point, e: &MouseMovedEvent, mode: TermMode) ->
} }
pub fn mouse_side(pos: Vector2F, cur_size: TerminalSize) -> alacritty_terminal::index::Direction { pub fn mouse_side(pos: Vector2F, cur_size: TerminalSize) -> alacritty_terminal::index::Direction {
if cur_size.cell_width as usize == 0 {
return Side::Right;
}
let x = pos.0.x() as usize; let x = pos.0.x() as usize;
let cell_x = x.saturating_sub(cur_size.cell_width as usize) % cur_size.cell_width as usize; let cell_x = x.saturating_sub(cur_size.cell_width as usize) % cur_size.cell_width as usize;
let half_cell_width = (cur_size.cell_width / 2.0) as usize; let half_cell_width = (cur_size.cell_width / 2.0) as usize;