Fix key handling in AppView
- Now offering to menu if it has focus so that it can do its things. Essentially if menu is visible it take keys. - Relates #807
This commit is contained in:
@@ -107,6 +107,11 @@ public class AppView extends BoxView {
|
||||
}
|
||||
return KeyHandler.resultOf(event, consumed, null);
|
||||
};
|
||||
|
||||
// if menu has focus, take from there
|
||||
if (menu != null && menu.hasFocus()) {
|
||||
return menu.getKeyHandler();
|
||||
}
|
||||
KeyHandler otherHandler = main != null ? main.getKeyHandler() : super.getKeyHandler();
|
||||
return otherHandler.thenIfNotConsumed(handler);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@ package org.springframework.shell.component.view.control;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.shell.component.view.event.KeyEvent.Key;
|
||||
import org.springframework.shell.component.view.event.KeyHandler.KeyHandlerResult;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -63,6 +66,50 @@ class AppViewTests extends AbstractViewTests {
|
||||
|
||||
}
|
||||
|
||||
@Nested
|
||||
class Events {
|
||||
|
||||
@Test
|
||||
void shouldOfferKeysToMenuIfHavingFocus() {
|
||||
BoxView smenu = spy(new BoxView());
|
||||
BoxView smain = spy(new BoxView());
|
||||
BoxView sstatus = spy(new BoxView());
|
||||
AppView sview = new AppView(smain, smenu, sstatus);
|
||||
|
||||
smenu.focus(smenu, true);
|
||||
|
||||
KeyHandlerResult result = handleKey(sview, Key.CursorRight);
|
||||
assertThat(result).isNotNull().satisfies(r -> {
|
||||
assertThat(r.event()).isNotNull();
|
||||
assertThat(r.consumed()).isFalse();
|
||||
assertThat(r.focus()).isNull();
|
||||
assertThat(r.capture()).isNull();
|
||||
});
|
||||
|
||||
verify(smain, never()).getKeyHandler();
|
||||
verify(smenu).getKeyHandler();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldOfferKeysToMainIfMenuHaveNoFocus() {
|
||||
BoxView smenu = spy(new BoxView());
|
||||
BoxView smain = spy(new BoxView());
|
||||
BoxView sstatus = spy(new BoxView());
|
||||
AppView sview = new AppView(smain, smenu, sstatus);
|
||||
|
||||
KeyHandlerResult result = handleKey(sview, Key.CursorRight);
|
||||
assertThat(result).isNotNull().satisfies(r -> {
|
||||
assertThat(r.event()).isNotNull();
|
||||
assertThat(r.consumed()).isTrue();
|
||||
assertThat(r.focus()).isNull();
|
||||
assertThat(r.capture()).isNull();
|
||||
});
|
||||
|
||||
verify(smain).getKeyHandler();
|
||||
verify(smenu, never()).getKeyHandler();
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
class Visibility {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user