fix: handle components keydown and keyup actions
This commit is contained in:
@@ -146,8 +146,18 @@ class ComponentViewCtrl implements ComponentViewScope {
|
||||
identifier: 'component-view-' + Math.random(),
|
||||
areas: [this.component.area],
|
||||
actionHandler: (component, action, data) => {
|
||||
if (action === ComponentAction.SetSize) {
|
||||
this.application.componentManager!.handleSetSizeEvent(component, data);
|
||||
switch (action) {
|
||||
case (ComponentAction.SetSize):
|
||||
this.application.componentManager!.handleSetSizeEvent(component, data);
|
||||
break;
|
||||
case (ComponentAction.KeyDown):
|
||||
this.application.io.handleComponentKeyDown(data.keyboardModifier);
|
||||
break;
|
||||
case (ComponentAction.KeyUp):
|
||||
this.application.io.handleComponentKeyUp(data.keyboardModifier);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -50,37 +50,59 @@ export class IOService {
|
||||
(this.handleWindowBlur as unknown) = undefined;
|
||||
}
|
||||
|
||||
private addActiveModifier = (modifier: KeyboardModifier | undefined): void => {
|
||||
if (!modifier) {
|
||||
return;
|
||||
}
|
||||
switch (modifier) {
|
||||
case KeyboardModifier.Meta: {
|
||||
if (this.isMac) {
|
||||
this.activeModifiers.add(modifier);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KeyboardModifier.Ctrl: {
|
||||
if (!this.isMac) {
|
||||
this.activeModifiers.add(modifier);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
this.activeModifiers.add(modifier);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private removeActiveModifier = (modifier: KeyboardModifier | undefined): void => {
|
||||
if (!modifier) {
|
||||
return;
|
||||
}
|
||||
this.activeModifiers.delete(modifier);
|
||||
}
|
||||
|
||||
handleKeyDown = (event: KeyboardEvent): void => {
|
||||
for (const modifier of this.modifiersForEvent(event)) {
|
||||
switch (modifier) {
|
||||
case KeyboardModifier.Meta: {
|
||||
if (this.isMac) {
|
||||
this.activeModifiers.add(modifier);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KeyboardModifier.Ctrl: {
|
||||
if (!this.isMac) {
|
||||
this.activeModifiers.add(modifier);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
this.activeModifiers.add(modifier);
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.addActiveModifier(modifier);
|
||||
}
|
||||
this.notifyObserver(event, KeyboardKeyEvent.Down);
|
||||
};
|
||||
|
||||
handleComponentKeyDown = (modifier: KeyboardModifier | undefined): void => {
|
||||
this.addActiveModifier(modifier);
|
||||
}
|
||||
|
||||
handleKeyUp = (event: KeyboardEvent): void => {
|
||||
for (const modifier of this.modifiersForEvent(event)) {
|
||||
this.activeModifiers.delete(modifier);
|
||||
this.removeActiveModifier(modifier);
|
||||
}
|
||||
this.notifyObserver(event, KeyboardKeyEvent.Up);
|
||||
};
|
||||
|
||||
handleComponentKeyUp = (modifier: KeyboardModifier | undefined): void => {
|
||||
this.removeActiveModifier(modifier);
|
||||
}
|
||||
|
||||
handleWindowBlur = (): void => {
|
||||
for (const modifier of this.activeModifiers) {
|
||||
this.activeModifiers.delete(modifier);
|
||||
|
||||
Reference in New Issue
Block a user