File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -35,6 +35,9 @@ const FREEBUFF_MODEL_SELECTOR_MODELS: readonly FreebuffModelOption[] = [
3535 ...FREEBUFF_MODELS . filter ( ( model ) => model . id === DEFAULT_FREEBUFF_MODEL_ID ) ,
3636 ...FREEBUFF_MODELS . filter ( ( model ) => model . id !== DEFAULT_FREEBUFF_MODEL_ID ) ,
3737]
38+ const FREEBUFF_MODEL_SELECTOR_MODEL_IDS = FREEBUFF_MODEL_SELECTOR_MODELS . map (
39+ ( model ) => model . id ,
40+ )
3841
3942function formatSessionUnits ( units : number ) : string {
4043 return Number . isInteger ( units ) ? String ( units ) : units . toFixed ( 1 )
@@ -219,7 +222,6 @@ export const FreebuffModelSelector: React.FC = () => {
219222 const direction = freebuffModelNavigationDirectionForKey ( key )
220223 const isCommit =
221224 name === 'return' || name === 'enter' || name === 'space'
222- if ( ! direction && ! isCommit ) return
223225 if ( isCommit ) {
224226 if ( isJoinable ( focusedId ) && focusedId !== committedModelId ) {
225227 key . preventDefault ?.( )
@@ -230,7 +232,7 @@ export const FreebuffModelSelector: React.FC = () => {
230232 }
231233 if ( ! direction ) return
232234 const targetId = nextFreebuffModelId ( {
233- modelIds : FREEBUFF_MODEL_SELECTOR_MODELS . map ( ( model ) => model . id ) ,
235+ modelIds : FREEBUFF_MODEL_SELECTOR_MODEL_IDS ,
234236 focusedId,
235237 direction,
236238 } )
Original file line number Diff line number Diff line change 11export type FreebuffModelNavigationDirection = 'forward' | 'backward'
22
3+ const FORWARD_KEY_NAMES = new Set ( [ 'right' , 'down' ] )
4+ const BACKWARD_KEY_NAMES = new Set ( [ 'left' , 'up' ] )
5+ const FORWARD_TAB_SEQUENCES = new Set ( [ '\t' , '\x1b[9u' ] )
6+ const BACKWARD_TAB_SEQUENCES = new Set ( [
7+ '\x1b[Z' ,
8+ '\x1b[9;2u' ,
9+ '\x1b[27;2;9~' ,
10+ ] )
11+
312export function nextFreebuffModelId ( params : {
413 modelIds : readonly string [ ]
514 focusedId : string
@@ -24,17 +33,16 @@ export function freebuffModelNavigationDirectionForKey(key: {
2433 const name = ( key . name ?? '' ) . toLowerCase ( )
2534 const sequence = key . sequence ?? key . raw ?? ''
2635
27- if ( name === 'right' || name === 'down' ) return 'forward'
28- if ( name === 'left' || name === 'up' ) return 'backward'
36+ if ( FORWARD_KEY_NAMES . has ( name ) ) return 'forward'
37+ if ( BACKWARD_KEY_NAMES . has ( name ) ) return 'backward'
2938
30- const isShiftTab =
39+ if (
3140 ( name === 'tab' && Boolean ( key . shift ) ) ||
32- sequence === '\x1b[Z' ||
33- sequence === '\x1b[9;2u' ||
34- sequence === '\x1b[27;2;9~'
35- if ( isShiftTab ) return 'backward'
36-
37- if ( name === 'tab' || sequence === '\t' || sequence === '\x1b[9u' ) {
41+ BACKWARD_TAB_SEQUENCES . has ( sequence )
42+ ) {
43+ return 'backward'
44+ }
45+ if ( name === 'tab' || FORWARD_TAB_SEQUENCES . has ( sequence ) ) {
3846 return 'forward'
3947 }
4048
You can’t perform that action at this time.
0 commit comments