mirror of
https://github.com/aljazceru/notedeck.git
synced 2026-02-08 10:04:19 +01:00
Fix channel dialog freeze when pressing Enter
Fixed a deadlock issue where the application would freeze when pressing Enter to create or edit a channel. The problem was caused by creating the dialog action inside the ui.input() closure, which held a lock on the input state while executing action handler code. The fix moves the action creation outside the closure, following the same pattern used in other input handlers throughout the codebase. Now we only check if the key was pressed inside the closure and handle the action creation afterwards. This resolves the freeze while maintaining the same functionality when clicking the button, as button clicks don't hold input state locks.
This commit is contained in:
@@ -129,35 +129,37 @@ impl ChannelDialog {
|
||||
);
|
||||
|
||||
// Handle Escape key to close dialog
|
||||
ui.input(|i| {
|
||||
if i.key_pressed(egui::Key::Escape) {
|
||||
action = Some(ChannelDialogAction::Cancel);
|
||||
}
|
||||
// Handle Enter key when name is focused
|
||||
if i.key_pressed(egui::Key::Enter) && !hashtags_response.has_focus() {
|
||||
if !self.name.trim().is_empty() {
|
||||
let hashtags: Vec<String> = self
|
||||
.hashtags
|
||||
.split(',')
|
||||
.map(|s| s.trim().to_string())
|
||||
.filter(|s| !s.is_empty())
|
||||
.collect();
|
||||
let escape_pressed = ui.input(|i| i.key_pressed(egui::Key::Escape));
|
||||
let enter_pressed = ui.input(|i| i.key_pressed(egui::Key::Enter));
|
||||
|
||||
action = if let Some(index) = self.editing_index {
|
||||
Some(ChannelDialogAction::Edit {
|
||||
index,
|
||||
name: self.name.trim().to_string(),
|
||||
hashtags,
|
||||
})
|
||||
} else {
|
||||
Some(ChannelDialogAction::Create {
|
||||
name: self.name.trim().to_string(),
|
||||
hashtags,
|
||||
})
|
||||
};
|
||||
}
|
||||
if escape_pressed {
|
||||
action = Some(ChannelDialogAction::Cancel);
|
||||
}
|
||||
|
||||
// Handle Enter key when name is focused (not hashtags multiline field)
|
||||
if enter_pressed && !hashtags_response.has_focus() {
|
||||
if !self.name.trim().is_empty() {
|
||||
let hashtags: Vec<String> = self
|
||||
.hashtags
|
||||
.split(',')
|
||||
.map(|s| s.trim().to_string())
|
||||
.filter(|s| !s.is_empty())
|
||||
.collect();
|
||||
|
||||
action = if let Some(index) = self.editing_index {
|
||||
Some(ChannelDialogAction::Edit {
|
||||
index,
|
||||
name: self.name.trim().to_string(),
|
||||
hashtags,
|
||||
})
|
||||
} else {
|
||||
Some(ChannelDialogAction::Create {
|
||||
name: self.name.trim().to_string(),
|
||||
hashtags,
|
||||
})
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ui.add_space(24.0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user