Skip to content

Commit 1b77df6

Browse files
authored
Fix consume_shortcut calls not checking for focus (microsoft#298)
1 parent 09af110 commit 1b77df6

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/bin/edit/draw_editor.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ pub fn draw_handle_wants_close(ctx: &mut Context, state: &mut State) {
227227
ctx.attr_background_rgba(ctx.indexed(IndexedColor::Red));
228228
ctx.attr_foreground_rgba(ctx.indexed(IndexedColor::BrightWhite));
229229
{
230+
let contains_focus = ctx.contains_focus();
231+
230232
ctx.label("description", loc(LocId::UnsavedChangesDialogDescription));
231233
ctx.attr_padding(Rect::three(1, 2, 1));
232234

@@ -259,10 +261,12 @@ pub fn draw_handle_wants_close(ctx: &mut Context, state: &mut State) {
259261
}
260262

261263
// Handle accelerator shortcuts
262-
if ctx.consume_shortcut(vk::S) {
263-
action = Action::Save;
264-
} else if ctx.consume_shortcut(vk::N) {
265-
action = Action::Discard;
264+
if contains_focus {
265+
if ctx.consume_shortcut(vk::S) {
266+
action = Action::Save;
267+
} else if ctx.consume_shortcut(vk::N) {
268+
action = Action::Discard;
269+
}
266270
}
267271
}
268272
ctx.table_end();

src/bin/edit/draw_filepicker.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ pub fn draw_file_picker(ctx: &mut Context, state: &mut State) {
131131
ctx.attr_background_rgba(ctx.indexed(IndexedColor::Red));
132132
ctx.attr_foreground_rgba(ctx.indexed(IndexedColor::BrightWhite));
133133
{
134+
let contains_focus = ctx.contains_focus();
135+
134136
ctx.label("description", loc(LocId::FileOverwriteWarningDescription));
135137
ctx.attr_overflow(Overflow::TruncateTail);
136138
ctx.attr_padding(Rect::three(1, 2, 1));
@@ -153,9 +155,11 @@ pub fn draw_file_picker(ctx: &mut Context, state: &mut State) {
153155
}
154156
ctx.table_end();
155157

156-
save |= ctx.consume_shortcut(vk::Y);
157-
if ctx.consume_shortcut(vk::N) {
158-
state.file_picker_overwrite_warning = None;
158+
if contains_focus {
159+
save |= ctx.consume_shortcut(vk::Y);
160+
if ctx.consume_shortcut(vk::N) {
161+
state.file_picker_overwrite_warning = None;
162+
}
159163
}
160164
}
161165
if ctx.modal_end() {

src/bin/edit/draw_statusbar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub fn draw_statusbar(ctx: &mut Context, state: &mut State) {
9595
ctx.attr_padding(Rect::two(0, 1));
9696
ctx.table_set_cell_gap(Size { width: 1, height: 0 });
9797
{
98-
if ctx.consume_shortcut(vk::RETURN) {
98+
if ctx.contains_focus() && ctx.consume_shortcut(vk::RETURN) {
9999
ctx.toss_focus_up();
100100
}
101101

0 commit comments

Comments
 (0)