fix: base keyboard modifier state on latest event
This commit is contained in:
@@ -87,27 +87,37 @@ export class IOService {
|
||||
this.activeModifiers.delete(modifier);
|
||||
};
|
||||
|
||||
handleKeyDown = (event: KeyboardEvent): void => {
|
||||
for (const modifier of this.modifiersForEvent(event)) {
|
||||
public handleComponentKeyDown = (
|
||||
modifier: KeyboardModifier | undefined
|
||||
): void => {
|
||||
this.addActiveModifier(modifier);
|
||||
}
|
||||
};
|
||||
|
||||
public handleComponentKeyUp = (
|
||||
modifier: KeyboardModifier | undefined
|
||||
): void => {
|
||||
this.removeActiveModifier(modifier);
|
||||
};
|
||||
|
||||
private handleKeyDown = (event: KeyboardEvent): void => {
|
||||
this.updateAllModifiersFromEvent(event);
|
||||
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.removeActiveModifier(modifier);
|
||||
}
|
||||
private handleKeyUp = (event: KeyboardEvent): void => {
|
||||
this.updateAllModifiersFromEvent(event);
|
||||
this.notifyObserver(event, KeyboardKeyEvent.Up);
|
||||
};
|
||||
|
||||
handleComponentKeyUp = (modifier: KeyboardModifier | undefined): void => {
|
||||
private updateAllModifiersFromEvent(event: KeyboardEvent): void {
|
||||
for (const modifier of Object.values(KeyboardModifier)) {
|
||||
if (event.getModifierState(modifier)) {
|
||||
this.addActiveModifier(modifier);
|
||||
} else {
|
||||
this.removeActiveModifier(modifier);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handleWindowBlur = (): void => {
|
||||
for (const modifier of this.activeModifiers) {
|
||||
@@ -136,7 +146,7 @@ export class IOService {
|
||||
return eventModifiers;
|
||||
}
|
||||
|
||||
eventMatchesKeyAndModifiers(
|
||||
private eventMatchesKeyAndModifiers(
|
||||
event: KeyboardEvent,
|
||||
key: KeyboardKey | string,
|
||||
modifiers: KeyboardModifier[] = []
|
||||
|
||||
@@ -114,12 +114,14 @@ export class NotesState {
|
||||
|
||||
async selectNote(uuid: UuidString, userTriggered?: boolean): Promise<void> {
|
||||
const note = this.application.findItem(uuid) as SNNote;
|
||||
if (!note) {
|
||||
return;
|
||||
}
|
||||
|
||||
const hasMeta = this.io.activeModifiers.has(KeyboardModifier.Meta);
|
||||
const hasCtrl = this.io.activeModifiers.has(KeyboardModifier.Ctrl);
|
||||
const hasShift = this.io.activeModifiers.has(KeyboardModifier.Shift);
|
||||
|
||||
if (note) {
|
||||
if (userTriggered && (hasMeta || hasCtrl)) {
|
||||
if (this.selectedNotes[uuid]) {
|
||||
delete this.selectedNotes[uuid];
|
||||
@@ -151,7 +153,6 @@ export class NotesState {
|
||||
await this.openNote(Object.keys(this.selectedNotes)[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async openNote(noteUuid: string): Promise<void> {
|
||||
if (this.activeNoteController?.note?.uuid === noteUuid) {
|
||||
|
||||
Reference in New Issue
Block a user