mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
refactor(settings): key code & controlled component
This commit is contained in:
parent
126c1226b7
commit
46436b0575
2 changed files with 3 additions and 6 deletions
|
|
@ -21,7 +21,7 @@ function detectOS() {
|
|||
}
|
||||
|
||||
function friendlyFormatShortcut(shortcut) {
|
||||
if (!shortcut) return
|
||||
if (typeof shortcut !== 'string') return ''
|
||||
const OS = detectOS()
|
||||
if (OS === OperatingSystems.Windows) {
|
||||
return shortcut.replace(/meta/, 'win')
|
||||
|
|
@ -158,9 +158,9 @@ export default class SettingsBar extends React.Component {
|
|||
<input
|
||||
className={'toggle-shortcut-input form-control'}
|
||||
placeholder={'focus here and press the shortcut keys'}
|
||||
default={''}
|
||||
value={friendlyFormatShortcut(toggleShowSideBarShortcut)}
|
||||
onKeyDown={this.onShortCutInputKeyDown}
|
||||
readOnly
|
||||
/>
|
||||
<button className={'btn'} onClick={this.saveShortcut}>
|
||||
Save
|
||||
|
|
|
|||
|
|
@ -35,15 +35,12 @@ function parse(keysString) {
|
|||
function parseKeyCode(code) {
|
||||
return code
|
||||
.toLowerCase()
|
||||
.replace(/(left|right)$/, '')
|
||||
.replace(/^control$/, 'ctrl')
|
||||
.replace(/^digit/, '')
|
||||
.replace(/^key/, '')
|
||||
}
|
||||
|
||||
function parseEvent(e) {
|
||||
const { altKey: alt, shiftKey: shift, metaKey: meta, ctrlKey: ctrl } = e
|
||||
const code = parseKeyCode(e.code)
|
||||
const code = parseKeyCode(e.key)
|
||||
const keys = { meta, ctrl, shift, alt, [code]: true }
|
||||
const combination = parse(
|
||||
Object.entries(keys)
|
||||
|
|
|
|||
Loading…
Reference in a new issue