HotKey can set focus

- Fix AbstractView to return focus info for hotkey handler
- TerminalUI sets focus from returned key handling
  for hotkeys
- Fixes #881
This commit is contained in:
Janne Valkealahti
2023-10-08 09:19:47 +01:00
parent edddc0b2e8
commit b6d1958949
4 changed files with 57 additions and 1 deletions

View File

@@ -273,6 +273,9 @@ public class TerminalUI implements ViewService {
if (handler != null) {
KeyHandlerResult result = handler.handle(KeyHandler.argsOf(event));
if (result.consumed()) {
if (result.focus() != null) {
setFocus(result.focus());
}
return;
}
}

View File

@@ -189,16 +189,18 @@ public abstract class AbstractView extends AbstractControl implements View {
log.trace("getHotKeyHandler() {}", this);
KeyHandler handler = args -> {
KeyEvent event = args.event();
View view = null;
boolean consumed = false;
Integer key = event.key();
if (key != null) {
KeyBindingValue keyBindingValue = getHotKeyBindings().get(key);
if (keyBindingValue != null) {
view = this;
consumed = dispatchKeyRunCommand(event, keyBindingValue);
}
}
return KeyHandler.resultOf(event, consumed, null);
return KeyHandler.resultOf(event, consumed, view);
};
return handler;
}