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(),
|
identifier: 'component-view-' + Math.random(),
|
||||||
areas: [this.component.area],
|
areas: [this.component.area],
|
||||||
actionHandler: (component, action, data) => {
|
actionHandler: (component, action, data) => {
|
||||||
if (action === ComponentAction.SetSize) {
|
switch (action) {
|
||||||
this.application.componentManager!.handleSetSizeEvent(component, data);
|
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;
|
(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 => {
|
handleKeyDown = (event: KeyboardEvent): void => {
|
||||||
for (const modifier of this.modifiersForEvent(event)) {
|
for (const modifier of this.modifiersForEvent(event)) {
|
||||||
switch (modifier) {
|
this.addActiveModifier(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.notifyObserver(event, KeyboardKeyEvent.Down);
|
this.notifyObserver(event, KeyboardKeyEvent.Down);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
handleComponentKeyDown = (modifier: KeyboardModifier | undefined): void => {
|
||||||
|
this.addActiveModifier(modifier);
|
||||||
|
}
|
||||||
|
|
||||||
handleKeyUp = (event: KeyboardEvent): void => {
|
handleKeyUp = (event: KeyboardEvent): void => {
|
||||||
for (const modifier of this.modifiersForEvent(event)) {
|
for (const modifier of this.modifiersForEvent(event)) {
|
||||||
this.activeModifiers.delete(modifier);
|
this.removeActiveModifier(modifier);
|
||||||
}
|
}
|
||||||
this.notifyObserver(event, KeyboardKeyEvent.Up);
|
this.notifyObserver(event, KeyboardKeyEvent.Up);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
handleComponentKeyUp = (modifier: KeyboardModifier | undefined): void => {
|
||||||
|
this.removeActiveModifier(modifier);
|
||||||
|
}
|
||||||
|
|
||||||
handleWindowBlur = (): void => {
|
handleWindowBlur = (): void => {
|
||||||
for (const modifier of this.activeModifiers) {
|
for (const modifier of this.activeModifiers) {
|
||||||
this.activeModifiers.delete(modifier);
|
this.activeModifiers.delete(modifier);
|
||||||
|
|||||||
Reference in New Issue
Block a user