diff options
author | Vijay A <vraravam@users.noreply.github.com> | 2023-05-28 22:11:03 +0530 |
---|---|---|
committer | Vijay Aravamudhan <vraravam@users.noreply.github.com> | 2023-05-28 22:25:33 +0530 |
commit | b631f0f664dc85c81032b02eebdd8eb1e8796a81 (patch) | |
tree | e4a50a32f7836953c0a6af34389fe9898e24215a | |
parent | Fix issues reported by sonarqube linter (diff) | |
download | ferdium-app-b631f0f664dc85c81032b02eebdd8eb1e8796a81.tar.gz ferdium-app-b631f0f664dc85c81032b02eebdd8eb1e8796a81.tar.zst ferdium-app-b631f0f664dc85c81032b02eebdd8eb1e8796a81.zip |
Allow the 10th service to also be accessible via keyboard shortcut combo
-rw-r--r-- | src/components/services/tabs/TabItem.tsx | 14 | ||||
-rw-r--r-- | src/features/workspaces/components/WorkspaceDrawerItem.tsx | 12 | ||||
-rw-r--r-- | src/jsUtils.ts | 7 | ||||
-rw-r--r-- | src/lib/Menu.ts | 3 | ||||
-rw-r--r-- | test/jsUtils.test.ts | 22 |
5 files changed, 43 insertions, 15 deletions
diff --git a/src/components/services/tabs/TabItem.tsx b/src/components/services/tabs/TabItem.tsx index 289597db9..c883066ce 100644 --- a/src/components/services/tabs/TabItem.tsx +++ b/src/components/services/tabs/TabItem.tsx | |||
@@ -15,6 +15,7 @@ import globalMessages from '../../../i18n/globalMessages'; | |||
15 | import Icon from '../../ui/icon'; | 15 | import Icon from '../../ui/icon'; |
16 | import { Stores } from '../../../@types/stores.types'; | 16 | import { Stores } from '../../../@types/stores.types'; |
17 | import MenuItemConstructorOptions = Electron.MenuItemConstructorOptions; | 17 | import MenuItemConstructorOptions = Electron.MenuItemConstructorOptions; |
18 | import { acceleratorString } from '../../../jsUtils'; | ||
18 | 19 | ||
19 | const IS_SERVICE_DEBUGGING_ENABLED = ( | 20 | const IS_SERVICE_DEBUGGING_ENABLED = ( |
20 | localStorage.getItem('debug') || '' | 21 | localStorage.getItem('debug') || '' |
@@ -358,11 +359,10 @@ class TabItem extends Component<IProps, IState> { | |||
358 | onKeyDown={noop} | 359 | onKeyDown={noop} |
359 | role="presentation" | 360 | role="presentation" |
360 | onContextMenu={() => menu.popup()} | 361 | onContextMenu={() => menu.popup()} |
361 | data-tip={`${service.name} ${ | 362 | data-tip={`${service.name} ${acceleratorString( |
362 | shortcutIndex <= 9 | 363 | shortcutIndex, |
363 | ? `(${cmdOrCtrlShortcutKey(false)}+${shortcutIndex})` | 364 | cmdOrCtrlShortcutKey(false), |
364 | : '' | 365 | )}`} |
365 | }`} | ||
366 | > | 366 | > |
367 | <img src={service.icon} className="tab-item__icon" alt="" /> | 367 | <img src={service.icon} className="tab-item__icon" alt="" /> |
368 | {showServiceNameSetting && ( | 368 | {showServiceNameSetting && ( |
@@ -407,8 +407,8 @@ class TabItem extends Component<IProps, IState> { | |||
407 | /> | 407 | /> |
408 | </> | 408 | </> |
409 | )} | 409 | )} |
410 | {shortcutIndex <= 9 && this.state.showShortcutIndex && ( | 410 | {shortcutIndex <= 10 && this.state.showShortcutIndex && ( |
411 | <span className="tab-item__shortcut-index">{shortcutIndex}</span> | 411 | <span className="tab-item__shortcut-index">{shortcutIndex % 10}</span> |
412 | )} | 412 | )} |
413 | </li> | 413 | </li> |
414 | ); | 414 | ); |
diff --git a/src/features/workspaces/components/WorkspaceDrawerItem.tsx b/src/features/workspaces/components/WorkspaceDrawerItem.tsx index 74ca2797d..cf8c3b2ba 100644 --- a/src/features/workspaces/components/WorkspaceDrawerItem.tsx +++ b/src/features/workspaces/components/WorkspaceDrawerItem.tsx | |||
@@ -7,6 +7,7 @@ import { noop } from 'lodash'; | |||
7 | import { Menu } from '@electron/remote'; | 7 | import { Menu } from '@electron/remote'; |
8 | import { MenuItemConstructorOptions } from 'electron'; | 8 | import { MenuItemConstructorOptions } from 'electron'; |
9 | import { altKey, cmdOrCtrlShortcutKey } from '../../../environment'; | 9 | import { altKey, cmdOrCtrlShortcutKey } from '../../../environment'; |
10 | import { acceleratorString } from '../../../jsUtils'; | ||
10 | 11 | ||
11 | const messages = defineMessages({ | 12 | const messages = defineMessages({ |
12 | noServicesAddedYet: { | 13 | noServicesAddedYet: { |
@@ -118,13 +119,10 @@ class WorkspaceDrawerItem extends Component<IProps> { | |||
118 | } | 119 | } |
119 | }} | 120 | }} |
120 | onKeyDown={noop} | 121 | onKeyDown={noop} |
121 | data-tip={`${ | 122 | data-tip={acceleratorString( |
122 | shortcutIndex <= 9 | 123 | shortcutIndex, |
123 | ? `(${cmdOrCtrlShortcutKey(false)}+${altKey( | 124 | `${cmdOrCtrlShortcutKey(false)}+${altKey(false)}`, |
124 | false, | 125 | )} |
125 | )}+${shortcutIndex})` | ||
126 | : '' | ||
127 | }`} | ||
128 | > | 126 | > |
129 | <span | 127 | <span |
130 | className={classnames([ | 128 | className={classnames([ |
diff --git a/src/jsUtils.ts b/src/jsUtils.ts index 47473a538..ac7258644 100644 --- a/src/jsUtils.ts +++ b/src/jsUtils.ts | |||
@@ -23,3 +23,10 @@ export const safeParseInt = (text: string | number | undefined | null) => { | |||
23 | const adjustedNumber = Number.isNaN(parsedNumber) ? 0 : parsedNumber; | 23 | const adjustedNumber = Number.isNaN(parsedNumber) ? 0 : parsedNumber; |
24 | return Math.max(adjustedNumber, 0); | 24 | return Math.max(adjustedNumber, 0); |
25 | }; | 25 | }; |
26 | |||
27 | export const acceleratorString = ( | ||
28 | index: number, | ||
29 | keyCombo: string, | ||
30 | prefix: string = '(', | ||
31 | suffix: string = ')', | ||
32 | ) => (index <= 10 ? `${prefix}${keyCombo}+${index % 10}${suffix}` : undefined); | ||
diff --git a/src/lib/Menu.ts b/src/lib/Menu.ts index 936785b9b..d611d5f3e 100644 --- a/src/lib/Menu.ts +++ b/src/lib/Menu.ts | |||
@@ -47,6 +47,7 @@ import { timestamp, gitHashShort, gitBranch } from '../buildInfo.json'; | |||
47 | import Service from '../models/Service'; | 47 | import Service from '../models/Service'; |
48 | import { StoresProps } from '../@types/ferdium-components.types'; | 48 | import { StoresProps } from '../@types/ferdium-components.types'; |
49 | import { RealStores } from '../stores'; | 49 | import { RealStores } from '../stores'; |
50 | import { acceleratorString } from '../jsUtils'; | ||
50 | 51 | ||
51 | const menuItems = defineMessages({ | 52 | const menuItems = defineMessages({ |
52 | edit: { | 53 | edit: { |
@@ -1101,7 +1102,7 @@ class FranzMenu implements StoresProps { | |||
1101 | for (const [i, service] of services.allDisplayed.entries()) { | 1102 | for (const [i, service] of services.allDisplayed.entries()) { |
1102 | menu.push({ | 1103 | menu.push({ |
1103 | label: this._getServiceName(service), | 1104 | label: this._getServiceName(service), |
1104 | accelerator: i < 9 ? `${cmdOrCtrlShortcutKey()}+${i + 1}` : undefined, | 1105 | accelerator: acceleratorString(i + 1, cmdOrCtrlShortcutKey(), '', ''), |
1105 | type: 'radio', | 1106 | type: 'radio', |
1106 | checked: service.isActive, | 1107 | checked: service.isActive, |
1107 | click: () => { | 1108 | click: () => { |
diff --git a/test/jsUtils.test.ts b/test/jsUtils.test.ts index 7245d9a68..411ef28f9 100644 --- a/test/jsUtils.test.ts +++ b/test/jsUtils.test.ts | |||
@@ -127,4 +127,26 @@ describe('jsUtils', () => { | |||
127 | expect(jsUtils.safeParseInt(47.45)).toEqual(47); | 127 | expect(jsUtils.safeParseInt(47.45)).toEqual(47); |
128 | }); | 128 | }); |
129 | }); | 129 | }); |
130 | |||
131 | describe('acceleratorString', () => { | ||
132 | it('handles without prefix and suffix', () => { | ||
133 | expect(jsUtils.acceleratorString(5, 'abc')).toEqual('(abc+5)'); | ||
134 | }); | ||
135 | |||
136 | it('handles index = 0', () => { | ||
137 | expect(jsUtils.acceleratorString(0, 'abc')).toEqual('(abc+0)'); | ||
138 | }); | ||
139 | |||
140 | it('handles index = 1', () => { | ||
141 | expect(jsUtils.acceleratorString(1, 'abc')).toEqual('(abc+1)'); | ||
142 | }); | ||
143 | |||
144 | it('handles index = 10', () => { | ||
145 | expect(jsUtils.acceleratorString(10, 'abc')).toEqual('(abc+0)'); | ||
146 | }); | ||
147 | |||
148 | it('handles index = 11', () => { | ||
149 | expect(jsUtils.acceleratorString(11, 'abc')).toEqual(undefined); | ||
150 | }); | ||
151 | }); | ||
130 | }); | 152 | }); |