You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently working on an app that utilizes a custom service for shortcuts. This service includes a scope that indicates the app's current state. It would greatly benefit me to have a centrally managed scope for easier migration. Is there a solution available that I might have missed?
My current ShortcutsService;
importRouterServicefrom'@ember/routing/router-service';importService,{injectasservice}from'@ember/service';import{tracked}from'@glimmer/tracking';importCommandPaletteServicefrom'./command-palette';importEventBusServicefrom'./event-bus';import{ShortCutScope,ShortCut}from'../types/app';/** * ShortcutsService */exportdefaultclassShortcutsServiceextendsService{
@servicedeclarerouter: RouterService;
@servicedeclareeventBus: EventBusService;// prettier-ignore
@service('command-palette')declarecommandPaletteService: CommandPaletteService;// Defaults
@trackedscope=ShortCutScope.All;// prettier-ignoreshortcuts: ShortCut[]=[{shortcut: 'command+1',scope: ShortCutScope.All,callback: ()=>this.router.transitionTo('documents')},{shortcut: 'command+2',scope: ShortCutScope.All,callback: ()=>this.router.transitionTo('import')},{shortcut: 'command+3',scope: ShortCutScope.All,callback: ()=>this.router.transitionTo('senders')},{shortcut: 'command+,',scope: ShortCutScope.All,callback: ()=>this.router.transitionTo('settings')},{shortcut: 'command+k',scope: ShortCutScope.All,callback: ()=>this.commandPaletteService.open()},{shortcut: 'escape',scope: ShortCutScope.CommandPalette,callback: ()=>this.commandPaletteService.close()},{shortcut: 'arrowup',scope: ShortCutScope.CommandPalette,callback: ()=>this.commandPaletteService.indexChange(false)},{shortcut: 'arrowdown',scope: ShortCutScope.CommandPalette,callback: ()=>this.commandPaletteService.indexChange(true)},];// Id's of input elements that should not be filteredexcludedInputIds=['command-palette-input'];/** * Setup the shortcuts * @returns {void} */setup(): void{document.addEventListener('keydown',(event)=>{this.handleKeyDown(event);});}/** * Set the scope * @param {ShortCutScope} scope */setScope(scope: ShortCutScope): void{this.scope=scope;}/** * Get the scope * @returns {ShortCutScope} */getgetScope(): ShortCutScope{returnthis.scope;}/** * Handle key down event * @param {KeyboardEvent} event */handleKeyDown(event: KeyboardEvent): void{if(this.filterEvent(event)){return;}constshortcut=this.findShortcut(event);if(shortcut){event.preventDefault();event.stopPropagation();shortcut.callback();}}/** * Filter the event for input elements * * @param {KeyboardEvent} event */filterEvent(event: KeyboardEvent): boolean{consttarget=event.targetasHTMLElement;if(target.tagName==='INPUT'||target.tagName==='TEXTAREA'){if(this.excludedInputIds.includes(target.id)){returnfalse;}returntrue;}returnfalse;}/** * Find a shortcut * @param {KeyboardEvent} event * @returns {ShortCut | undefined} */findShortcut(event: KeyboardEvent): ShortCut|undefined{constkey=event.key.toLowerCase();constisCommand=event.metaKey||event.ctrlKey;constshortcut=`${isCommand ? 'command+' : ''}${key}`;returnthis.shortcuts.find((s)=>{return(s.shortcut===shortcut&&(s.scope===this.scope||s.scope===ShortCutScope.All));});}}// Don't remove this declaration: this is what enables TypeScript to resolve// this service using `Owner.lookup('service:shortcuts')`, as well// as to check when you pass the service name as an argument to the decorator,// like `@service('shortcuts') declare altName: ShortcutsService;`.declare module '@ember/service'{interfaceRegistry{shortcuts: ShortcutsService;}}
The text was updated successfully, but these errors were encountered:
Hallo,
I'm currently working on an app that utilizes a custom service for shortcuts. This service includes a scope that indicates the app's current state. It would greatly benefit me to have a centrally managed scope for easier migration. Is there a solution available that I might have missed?
My current ShortcutsService;
The text was updated successfully, but these errors were encountered: