Skip to content

Commit

Permalink
feat: support ctrl,alt,shift for sequence hotkey
Browse files Browse the repository at this point in the history
  • Loading branch information
JH committed Mar 7, 2022
1 parent cdbdaac commit ac0f78d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
</thead>
<tbody>
<tr class="hotkeys-table-help-shortcut" *ngFor="let hotkey of hotkeyGroup.hotkeys">
<td class="hotkeys-table-help-shortcut-description" width="75%">{{ hotkey.description }}</td>
<td class="hotkeys-table-help-shortcut-keys" width="25%">
<td class="hotkeys-table-help-shortcut-description" width="50%">{{ hotkey.description }}</td>
<td class="hotkeys-table-help-shortcut-keys" width="50%">
<kbd [innerHTML]="hotkey.keys | hotkeysShortcut"></kbd>
</td>
</tr>
Expand Down
14 changes: 8 additions & 6 deletions projects/ngneat/hotkeys/src/lib/hotkeys-shortcut.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ export class HotkeysShortcutPipe implements PipeTransform {
}
return value
.split('>')
.join(thenSeparator)
.split('.')
.map(c => c.toLowerCase())
.map(c => this.symbols[c] || c)
.join(dotSeparator)
.split('>');
.map(s =>
s
.split('.')
.map(c => c.toLowerCase())
.map(c => this.symbols[c] || c)
.join(dotSeparator)
)
.join(thenSeparator);
}

private getPlatformSymbols(platform): any {
Expand Down
7 changes: 6 additions & 1 deletion projects/ngneat/hotkeys/src/lib/hotkeys.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ export class HotkeysService {
const getObserver = (element: HTMLElement, eventName: string) => {
let sequence = '';
return fromEvent<KeyboardEvent>(element, eventName).pipe(
tap(e => (sequence = `${sequence}${sequence ? '>' : ''}${e.key}`)),
tap(
e =>
(sequence = `${sequence}${sequence ? '>' : ''}${e.ctrlKey ? 'control.' : ''}${e.altKey ? 'alt.' : ''}${
e.shiftKey ? 'shift.' : ''
}${e.key}`)
),
debounceTime(this.sequenceDebounce),
mergeMap(() => {
const resultSequence = sequence;
Expand Down
22 changes: 21 additions & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,28 @@ export class AppComponent implements AfterViewInit {
})
.subscribe(e => {
console.log('Test Sequence:', e);
});

this.hotkeys.removeShortcuts('g>t');
this.hotkeys
.addSequenceShortcut({
keys: 'control.b>control.,',
description: 'Expand All',
preventDefault: false,
group: 'Sequencing'
})
.subscribe(e => {
console.log('Test Sequence:', e);
});

this.hotkeys
.addSequenceShortcut({
keys: 'r>s',
description: 'Remove this sequence',
preventDefault: false,
group: 'Sequencing'
})
.subscribe(() => {
this.hotkeys.removeShortcuts('r>s');
});

this.hotkeys
Expand Down

0 comments on commit ac0f78d

Please sign in to comment.