Fix consume_shortcut calls not checking for focus (#298)

This commit is contained in:
Leonard Hecker
2025-05-27 03:22:27 +02:00
committed by GitHub
parent 09af110856
commit 1b77df656f
3 changed files with 16 additions and 8 deletions

View File

@@ -227,6 +227,8 @@ pub fn draw_handle_wants_close(ctx: &mut Context, state: &mut State) {
ctx.attr_background_rgba(ctx.indexed(IndexedColor::Red));
ctx.attr_foreground_rgba(ctx.indexed(IndexedColor::BrightWhite));
{
let contains_focus = ctx.contains_focus();
ctx.label("description", loc(LocId::UnsavedChangesDialogDescription));
ctx.attr_padding(Rect::three(1, 2, 1));
@@ -259,10 +261,12 @@ pub fn draw_handle_wants_close(ctx: &mut Context, state: &mut State) {
}
// Handle accelerator shortcuts
if ctx.consume_shortcut(vk::S) {
action = Action::Save;
} else if ctx.consume_shortcut(vk::N) {
action = Action::Discard;
if contains_focus {
if ctx.consume_shortcut(vk::S) {
action = Action::Save;
} else if ctx.consume_shortcut(vk::N) {
action = Action::Discard;
}
}
}
ctx.table_end();

View File

@@ -131,6 +131,8 @@ pub fn draw_file_picker(ctx: &mut Context, state: &mut State) {
ctx.attr_background_rgba(ctx.indexed(IndexedColor::Red));
ctx.attr_foreground_rgba(ctx.indexed(IndexedColor::BrightWhite));
{
let contains_focus = ctx.contains_focus();
ctx.label("description", loc(LocId::FileOverwriteWarningDescription));
ctx.attr_overflow(Overflow::TruncateTail);
ctx.attr_padding(Rect::three(1, 2, 1));
@@ -153,9 +155,11 @@ pub fn draw_file_picker(ctx: &mut Context, state: &mut State) {
}
ctx.table_end();
save |= ctx.consume_shortcut(vk::Y);
if ctx.consume_shortcut(vk::N) {
state.file_picker_overwrite_warning = None;
if contains_focus {
save |= ctx.consume_shortcut(vk::Y);
if ctx.consume_shortcut(vk::N) {
state.file_picker_overwrite_warning = None;
}
}
}
if ctx.modal_end() {

View File

@@ -95,7 +95,7 @@ pub fn draw_statusbar(ctx: &mut Context, state: &mut State) {
ctx.attr_padding(Rect::two(0, 1));
ctx.table_set_cell_gap(Size { width: 1, height: 0 });
{
if ctx.consume_shortcut(vk::RETURN) {
if ctx.contains_focus() && ctx.consume_shortcut(vk::RETURN) {
ctx.toss_focus_up();
}