@@ -42,27 +42,14 @@ export const matchAuxiliaryHotKey = (hotKey: string, event: KeyboardEvent) => {
4242 return true ;
4343} ;
4444
45- /** 将快捷键字符串拆分为修饰键与主键,例如 ⌥F10 → ["⌥", "F10"] */
46- const parseHotKeyTokens = ( hotKey : string ) : string [ ] => {
47- const modifiers : string [ ] = [ ] ;
48- let i = 0 ;
49- while ( i < hotKey . length && "⌃⌥⇧⌘" . includes ( hotKey [ i ] ) ) {
50- modifiers . push ( hotKey [ i ] ) ;
51- i ++ ;
52- }
53- const rest = hotKey . slice ( i ) ;
54- if ( ! rest ) {
55- return modifiers ;
56- }
57- for ( const key of [ "PageUp" , "PageDown" , "Home" , "End" ] ) {
58- if ( rest === key ) {
59- return [ ...modifiers , key ] ;
45+ const replaceDirect = ( hotKey : string , keyCode : string ) => {
46+ const hotKeys = hotKey . replace ( keyCode , Constants . ZWSP ) . split ( "" ) ;
47+ hotKeys . forEach ( ( item , index ) => {
48+ if ( item === Constants . ZWSP ) {
49+ hotKeys [ index ] = keyCode ;
6050 }
61- }
62- if ( / ^ F (?: 1 [ 0 - 2 ] | [ 1 - 9 ] ) $ / . test ( rest ) ) {
63- return [ ...modifiers , rest ] ;
64- }
65- return [ ...modifiers , rest ] ;
51+ } ) ;
52+ return hotKeys ;
6653} ;
6754
6855export const matchHotKey = ( hotKey : string , event : KeyboardEvent ) => {
@@ -90,7 +77,26 @@ export const matchHotKey = (hotKey: string, event: KeyboardEvent) => {
9077 return false ;
9178 }
9279
93- const hotKeys = parseHotKeyTokens ( hotKey ) ;
80+ let hotKeys = hotKey . split ( "" ) ;
81+ if ( hotKey . indexOf ( "F" ) > - 1 ) {
82+ hotKeys . forEach ( ( item , index ) => {
83+ if ( item === "F" ) {
84+ // F1-F12
85+ hotKeys [ index ] = "F" + hotKeys . splice ( index + 1 , 1 ) ;
86+ if ( hotKeys [ index + 1 ] ) {
87+ hotKeys [ index + 1 ] += hotKeys . splice ( index + 1 , 1 ) ;
88+ }
89+ }
90+ } ) ;
91+ } else if ( hotKey . indexOf ( "PageUp" ) > - 1 ) {
92+ hotKeys = replaceDirect ( hotKey , "PageUp" ) ;
93+ } else if ( hotKey . indexOf ( "PageDown" ) > - 1 ) {
94+ hotKeys = replaceDirect ( hotKey , "PageDown" ) ;
95+ } else if ( hotKey . indexOf ( "Home" ) > - 1 ) {
96+ hotKeys = replaceDirect ( hotKey , "Home" ) ;
97+ } else if ( hotKey . indexOf ( "End" ) > - 1 ) {
98+ hotKeys = replaceDirect ( hotKey , "End" ) ;
99+ }
94100
95101 // 是否匹配 ⇧[]
96102 if ( hotKey . startsWith ( "⇧" ) && hotKeys . length === 2 ) {
0 commit comments