aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Vijay A <vraravam@users.noreply.github.com>2023-05-28 22:11:03 +0530
committerLibravatar Vijay Aravamudhan <vraravam@users.noreply.github.com>2023-05-28 22:25:33 +0530
commitb631f0f664dc85c81032b02eebdd8eb1e8796a81 (patch)
treee4a50a32f7836953c0a6af34389fe9898e24215a /src
parentFix issues reported by sonarqube linter (diff)
downloadferdium-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
Diffstat (limited to 'src')
-rw-r--r--src/components/services/tabs/TabItem.tsx14
-rw-r--r--src/features/workspaces/components/WorkspaceDrawerItem.tsx12
-rw-r--r--src/jsUtils.ts7
-rw-r--r--src/lib/Menu.ts3
4 files changed, 21 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';
15import Icon from '../../ui/icon'; 15import Icon from '../../ui/icon';
16import { Stores } from '../../../@types/stores.types'; 16import { Stores } from '../../../@types/stores.types';
17import MenuItemConstructorOptions = Electron.MenuItemConstructorOptions; 17import MenuItemConstructorOptions = Electron.MenuItemConstructorOptions;
18import { acceleratorString } from '../../../jsUtils';
18 19
19const IS_SERVICE_DEBUGGING_ENABLED = ( 20const 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';
7import { Menu } from '@electron/remote'; 7import { Menu } from '@electron/remote';
8import { MenuItemConstructorOptions } from 'electron'; 8import { MenuItemConstructorOptions } from 'electron';
9import { altKey, cmdOrCtrlShortcutKey } from '../../../environment'; 9import { altKey, cmdOrCtrlShortcutKey } from '../../../environment';
10import { acceleratorString } from '../../../jsUtils';
10 11
11const messages = defineMessages({ 12const 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
27export 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';
47import Service from '../models/Service'; 47import Service from '../models/Service';
48import { StoresProps } from '../@types/ferdium-components.types'; 48import { StoresProps } from '../@types/ferdium-components.types';
49import { RealStores } from '../stores'; 49import { RealStores } from '../stores';
50import { acceleratorString } from '../jsUtils';
50 51
51const menuItems = defineMessages({ 52const 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: () => {