Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/bin/edit/draw_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this the responsibility of the caller of consume_shortcut? That means every context by default can consume a shortcut, even if it's not focused?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I figured that this may sometimes be useful. Elsewhere I already mentioned that we should ideally modify consume_shortcut to do this for us. The only question is whether it checks whether the last node or the current (parent) node has focus. Sometimes you want one behavior sometimes the other.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough!

if ctx.consume_shortcut(vk::S) {
action = Action::Save;
} else if ctx.consume_shortcut(vk::N) {
action = Action::Discard;
}
}
}
ctx.table_end();
Expand Down
10 changes: 7 additions & 3 deletions src/bin/edit/draw_filepicker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/bin/edit/draw_statusbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down