@@ -173,6 +173,7 @@ impl ApplicationHandler<AppEvent> for App {
173173 WindowEvent :: Resized ( size) => {
174174 state. resize ( size. width , size. height ) ;
175175 }
176+ WindowEvent :: ModifiersChanged ( m) => state. modifiers = m,
176177 WindowEvent :: CursorMoved { position, .. } => {
177178 if state. layout . is_none ( ) {
178179 return ;
@@ -378,50 +379,21 @@ impl ApplicationHandler<AppEvent> for App {
378379 if !state. address_bar_active {
379380 match ( code, key_state) {
380381 ( KeyCode :: Escape , ElementState :: Pressed ) => event_loop. exit ( ) ,
381- (
382- KeyCode :: Digit0
383- | KeyCode :: Digit1
384- | KeyCode :: Digit2
385- | KeyCode :: Digit3
386- | KeyCode :: Digit4
387- | KeyCode :: Digit5
388- | KeyCode :: Digit6
389- | KeyCode :: Digit7
390- | KeyCode :: Digit8
391- | KeyCode :: Digit9 ,
392- ElementState :: Pressed ,
393- ) => {
394- let digit = match code {
395- KeyCode :: Digit0 => 0 ,
396- KeyCode :: Digit1 => 1 ,
397- KeyCode :: Digit2 => 2 ,
398- KeyCode :: Digit3 => 3 ,
399- KeyCode :: Digit4 => 4 ,
400- KeyCode :: Digit5 => 5 ,
401- KeyCode :: Digit6 => 6 ,
402- KeyCode :: Digit7 => 7 ,
403- KeyCode :: Digit8 => 8 ,
404- KeyCode :: Digit9 => 9 ,
405- _ => unreachable ! ( ) ,
406- } ;
407-
408- if digit < state. tab_datas . len ( ) {
409- let tab_data = & state. tab_datas [ digit] ;
410-
411- state. active_tab = digit;
412-
413- if let Some ( callbacks) = & self . callbacks {
414- ( callbacks. link_callback ) ( & tab_data. url ) ;
382+ ( KeyCode :: KeyT , ElementState :: Pressed ) => {
383+ if cfg ! ( target_os = "macos" ) {
384+ if !state. modifiers . state ( ) . super_key ( ) {
385+ return ;
386+ }
387+ } else {
388+ if !state. modifiers . state ( ) . control_key ( ) {
389+ return ;
415390 }
416391 }
417- }
418- ( KeyCode :: Minus , ElementState :: Pressed ) => {
392+
419393 if let Some ( state) = & mut self . state {
420394 state. tab_datas . insert (
421395 state. active_tab + 1 ,
422- TabData :: empty_from ( String :: from (
423- "https://flavorless.hackclub.com/" ,
424- ) ) ,
396+ TabData :: empty_from ( String :: from ( "harbor:new" ) ) ,
425397 ) ;
426398
427399 state. active_tab += 1 ;
@@ -432,6 +404,34 @@ impl ApplicationHandler<AppEvent> for App {
432404 }
433405 }
434406 }
407+ ( KeyCode :: Tab , ElementState :: Pressed ) => {
408+ if !state. modifiers . state ( ) . alt_key ( ) {
409+ return ;
410+ }
411+
412+ let direction = if state. modifiers . state ( ) . shift_key ( ) {
413+ -1
414+ } else {
415+ 1
416+ } ;
417+
418+ if key_state == ElementState :: Pressed {
419+ let num_tabs = state. tab_datas . len ( ) ;
420+
421+ if num_tabs == 0 {
422+ return ;
423+ }
424+
425+ state. active_tab = ( ( state. active_tab as isize + direction)
426+ . rem_euclid ( num_tabs as isize ) )
427+ as usize ;
428+
429+ if let Some ( callbacks) = & self . callbacks {
430+ let tab_data = & state. tab_datas [ state. active_tab ] ;
431+ ( callbacks. open_tab ) ( tab_data) ;
432+ }
433+ }
434+ }
435435 _ => { }
436436 }
437437 } else {
0 commit comments