@@ -34,18 +34,18 @@ import { _t } from "../../../../../languageHandler";
34
34
import AccessibleButton , { ButtonEvent } from "../../../elements/AccessibleButton" ;
35
35
import { openLinkModal } from "./LinkModal" ;
36
36
import { useComposerContext } from "../ComposerContext" ;
37
- import { IS_MAC , Key } from "../../../../../Keyboard " ;
38
- import { ALTERNATE_KEY_NAME } from "../../../../../accessibility/KeyboardShortcuts " ;
37
+ import { KeyboardShortcut } from "../../../settings/KeyboardShortcut " ;
38
+ import { KeyCombo } from "../../../../../KeyBindingsManager " ;
39
39
40
40
interface ButtonProps {
41
41
icon : ReactNode ;
42
42
actionState : ActionState ;
43
43
onClick : MouseEventHandler < HTMLButtonElement > ;
44
44
label : string ;
45
- shortcut ?: string ;
45
+ keyCombo ?: KeyCombo ;
46
46
}
47
47
48
- function Button ( { label, shortcut , onClick, actionState, icon } : ButtonProps ) : JSX . Element {
48
+ function Button ( { label, keyCombo , onClick, actionState, icon } : ButtonProps ) : JSX . Element {
49
49
return (
50
50
< AccessibleButton
51
51
element = "button"
@@ -57,22 +57,18 @@ function Button({ label, shortcut, onClick, actionState, icon }: ButtonProps): J
57
57
mx_FormattingButtons_disabled : actionState === "disabled" ,
58
58
} ) }
59
59
title = { actionState === "disabled" ? undefined : label }
60
- caption = { shortcut }
60
+ caption = {
61
+ keyCombo && (
62
+ < KeyboardShortcut value = { keyCombo } className = "mx_FormattingButtons_Tooltip_KeyboardShortcut" />
63
+ )
64
+ }
61
65
placement = "top"
62
66
>
63
67
{ icon }
64
68
</ AccessibleButton >
65
69
) ;
66
70
}
67
71
68
- /**
69
- * Get the shortcut string for a given key.
70
- * @param key
71
- */
72
- function getShortcutFromKey ( key : string ) : string {
73
- return ( IS_MAC ? "⌘" : _t ( ALTERNATE_KEY_NAME [ Key . CONTROL ] ) ) + "+" + key ;
74
- }
75
-
76
72
interface FormattingButtonsProps {
77
73
composer : FormattingFunctions ;
78
74
actionStates : AllActionStates ;
@@ -86,21 +82,21 @@ export function FormattingButtons({ composer, actionStates }: FormattingButtonsP
86
82
< Button
87
83
actionState = { actionStates . bold }
88
84
label = { _t ( "composer|format_bold" ) }
89
- shortcut = { getShortcutFromKey ( "B" ) }
85
+ keyCombo = { { ctrlOrCmdKey : true , key : "b" } }
90
86
onClick = { ( ) => composer . bold ( ) }
91
87
icon = { < BoldIcon className = "mx_FormattingButtons_Icon" /> }
92
88
/>
93
89
< Button
94
90
actionState = { actionStates . italic }
95
91
label = { _t ( "composer|format_italic" ) }
96
- shortcut = { getShortcutFromKey ( "I" ) }
92
+ keyCombo = { { ctrlOrCmdKey : true , key : "i" } }
97
93
onClick = { ( ) => composer . italic ( ) }
98
94
icon = { < ItalicIcon className = "mx_FormattingButtons_Icon" /> }
99
95
/>
100
96
< Button
101
97
actionState = { actionStates . underline }
102
98
label = { _t ( "composer|format_underline" ) }
103
- shortcut = { getShortcutFromKey ( "U" ) }
99
+ keyCombo = { { ctrlOrCmdKey : true , key : "u" } }
104
100
onClick = { ( ) => composer . underline ( ) }
105
101
icon = { < UnderlineIcon className = "mx_FormattingButtons_Icon" /> }
106
102
/>
@@ -147,7 +143,7 @@ export function FormattingButtons({ composer, actionStates }: FormattingButtonsP
147
143
< Button
148
144
actionState = { actionStates . inlineCode }
149
145
label = { _t ( "composer|format_inline_code" ) }
150
- shortcut = { getShortcutFromKey ( "E" ) }
146
+ keyCombo = { { ctrlOrCmdKey : true , key : "e" } }
151
147
onClick = { ( ) => composer . inlineCode ( ) }
152
148
icon = { < InlineCodeIcon className = "mx_FormattingButtons_Icon" /> }
153
149
/>
0 commit comments