@@ -17,16 +17,18 @@ use glam::DVec2;
1717impl From < MappingVariant > for Mapping {
1818 fn from ( value : MappingVariant ) -> Self {
1919 match value {
20- MappingVariant :: Default => input_mappings ( ) ,
21- MappingVariant :: ZoomWithScroll => zoom_with_scroll ( ) ,
20+ MappingVariant :: Default => input_mappings ( false ) ,
21+ MappingVariant :: ZoomWithScroll => input_mappings ( true ) ,
2222 }
2323 }
2424}
2525
26- pub fn input_mappings ( ) -> Mapping {
26+ pub fn input_mappings ( zoom_with_scroll : bool ) -> Mapping {
2727 use InputMapperMessage :: * ;
2828 use Key :: * ;
2929
30+ let keyboard_platform = GLOBAL_PLATFORM . get ( ) . copied ( ) . unwrap_or_default ( ) . as_keyboard_platform_layout ( ) ;
31+
3032 // NOTICE:
3133 // If a new mapping you added here isn't working (and perhaps another lower-precedence one is instead), make sure to advertise
3234 // it as an available action in the respective message handler file (such as the bottom of `document_message_handler.rs`).
@@ -55,9 +57,9 @@ pub fn input_mappings() -> Mapping {
5557 entry!( KeyDown ( KeyZ ) ; modifiers=[ Accel , MouseLeft ] , action_dispatch=DocumentMessage :: Noop ) ,
5658 //
5759 // AppWindowMessage
58- entry!( KeyDown ( F11 ) ; active =cfg!( not ( target_os = "macos" ) ) , action_dispatch=AppWindowMessage :: Fullscreen ) ,
59- entry!( KeyDown ( KeyF ) ; modifiers=[ Accel , Meta ] , active =cfg!( target_os = "macos" ) , action_dispatch=AppWindowMessage :: Fullscreen ) ,
60- entry!( KeyDown ( KeyQ ) ; modifiers=[ Accel ] , active =cfg!( target_os = "macos" ) , action_dispatch=AppWindowMessage :: Close ) ,
60+ entry!( KeyDown ( F11 ) ; disabled =cfg!( target_os = "macos" ) , action_dispatch=AppWindowMessage :: Fullscreen ) ,
61+ entry!( KeyDown ( KeyF ) ; modifiers=[ Accel , Meta ] , disabled =cfg!( not ( target_os = "macos" ) ) , action_dispatch=AppWindowMessage :: Fullscreen ) ,
62+ entry!( KeyDown ( KeyQ ) ; modifiers=[ Accel ] , disabled =cfg!( not ( target_os = "macos" ) ) , action_dispatch=AppWindowMessage :: Close ) ,
6163 //
6264 // ClipboardMessage
6365 entry!( KeyDown ( KeyX ) ; modifiers=[ Accel ] , action_dispatch=ClipboardMessage :: Cut ) ,
@@ -421,10 +423,14 @@ pub fn input_mappings() -> Mapping {
421423 entry!( KeyDown ( FakeKeyPlus ) ; modifiers=[ Accel ] , canonical, action_dispatch=NavigationMessage :: CanvasZoomIncrease { center_on_mouse: false } ) ,
422424 entry!( KeyDown ( Equal ) ; modifiers=[ Accel ] , action_dispatch=NavigationMessage :: CanvasZoomIncrease { center_on_mouse: false } ) ,
423425 entry!( KeyDown ( Minus ) ; modifiers=[ Accel ] , action_dispatch=NavigationMessage :: CanvasZoomDecrease { center_on_mouse: false } ) ,
424- entry!( WheelScroll ; modifiers=[ Control ] , action_dispatch=NavigationMessage :: CanvasZoomMouseWheel ) ,
425- entry!( WheelScroll ; modifiers=[ Command ] , action_dispatch=NavigationMessage :: CanvasZoomMouseWheel ) ,
426- entry!( WheelScroll ; modifiers=[ Shift ] , action_dispatch=NavigationMessage :: CanvasPanMouseWheel { use_y_as_x: true } ) ,
427- entry!( WheelScroll ; action_dispatch=NavigationMessage :: CanvasPanMouseWheel { use_y_as_x: false } ) ,
426+ entry!( WheelScroll ; modifiers=[ Control ] , disabled=zoom_with_scroll, action_dispatch=NavigationMessage :: CanvasZoomMouseWheel ) ,
427+ entry!( WheelScroll ; modifiers=[ Command ] , disabled=zoom_with_scroll, action_dispatch=NavigationMessage :: CanvasZoomMouseWheel ) ,
428+ entry!( WheelScroll ; modifiers=[ Shift ] , disabled=zoom_with_scroll, action_dispatch=NavigationMessage :: CanvasPanMouseWheel { use_y_as_x: true } ) ,
429+ entry!( WheelScroll ; disabled=zoom_with_scroll, action_dispatch=NavigationMessage :: CanvasPanMouseWheel { use_y_as_x: false } ) ,
430+ // On Mac, the OS already converts Shift+scroll into horizontal scrolling so we have to reverse the behavior from normal to produce the same outcome
431+ entry!( WheelScroll ; modifiers=[ Control ] , disabled=!zoom_with_scroll, action_dispatch=NavigationMessage :: CanvasPanMouseWheel { use_y_as_x: keyboard_platform == KeyboardPlatformLayout :: Mac } ) ,
432+ entry!( WheelScroll ; modifiers=[ Shift ] , disabled=!zoom_with_scroll, action_dispatch=NavigationMessage :: CanvasPanMouseWheel { use_y_as_x: keyboard_platform != KeyboardPlatformLayout :: Mac } ) ,
433+ entry!( WheelScroll ; disabled=!zoom_with_scroll, action_dispatch=NavigationMessage :: CanvasZoomMouseWheel ) ,
428434 entry!( KeyDown ( PageUp ) ; modifiers=[ Shift ] , action_dispatch=NavigationMessage :: CanvasPanByViewportFraction { delta: DVec2 :: new( 1. , 0. ) } ) ,
429435 entry!( KeyDown ( PageDown ) ; modifiers=[ Shift ] , action_dispatch=NavigationMessage :: CanvasPanByViewportFraction { delta: DVec2 :: new( -1. , 0. ) } ) ,
430436 entry!( KeyDown ( PageUp ) ; action_dispatch=NavigationMessage :: CanvasPanByViewportFraction { delta: DVec2 :: new( 0. , 1. ) } ) ,
@@ -487,43 +493,3 @@ pub fn input_mappings() -> Mapping {
487493 pointer_shake,
488494 }
489495}
490-
491- /// Default mappings except that scrolling without modifier keys held down is bound to zooming instead of vertical panning
492- pub fn zoom_with_scroll ( ) -> Mapping {
493- use InputMapperMessage :: * ;
494-
495- // On Mac, the OS already converts Shift+scroll into horizontal scrolling so we have to reverse the behavior from normal to produce the same outcome
496- let keyboard_platform = GLOBAL_PLATFORM . get ( ) . copied ( ) . unwrap_or_default ( ) . as_keyboard_platform_layout ( ) ;
497-
498- let mut mapping = input_mappings ( ) ;
499-
500- let remove = [
501- entry ! ( WheelScroll ; modifiers=[ Control ] , action_dispatch=NavigationMessage :: CanvasZoomMouseWheel ) ,
502- entry ! ( WheelScroll ; modifiers=[ Command ] , action_dispatch=NavigationMessage :: CanvasZoomMouseWheel ) ,
503- entry ! ( WheelScroll ; modifiers=[ Shift ] , action_dispatch=NavigationMessage :: CanvasPanMouseWheel { use_y_as_x: true } ) ,
504- entry ! ( WheelScroll ; action_dispatch=NavigationMessage :: CanvasPanMouseWheel { use_y_as_x: false } ) ,
505- ] ;
506- let add = [
507- entry ! ( WheelScroll ; modifiers=[ Control ] , action_dispatch=NavigationMessage :: CanvasPanMouseWheel { use_y_as_x: keyboard_platform == KeyboardPlatformLayout :: Mac } ) ,
508- entry ! ( WheelScroll ; modifiers=[ Shift ] , action_dispatch=NavigationMessage :: CanvasPanMouseWheel { use_y_as_x: keyboard_platform != KeyboardPlatformLayout :: Mac } ) ,
509- entry ! ( WheelScroll ; action_dispatch=NavigationMessage :: CanvasZoomMouseWheel ) ,
510- ] ;
511-
512- apply_mapping_patch ( & mut mapping, remove, add) ;
513-
514- mapping
515- }
516-
517- fn apply_mapping_patch < ' a , const N : usize , const M : usize , const X : usize , const Y : usize > (
518- mapping : & mut Mapping ,
519- remove : impl IntoIterator < Item = & ' a [ & ' a [ MappingEntry ; N ] ; M ] > ,
520- add : impl IntoIterator < Item = & ' a [ & ' a [ MappingEntry ; X ] ; Y ] > ,
521- ) {
522- for entry in remove. into_iter ( ) . flat_map ( |inner| inner. iter ( ) ) . flat_map ( |inner| inner. iter ( ) ) {
523- mapping. remove ( entry) ;
524- }
525-
526- for entry in add. into_iter ( ) . flat_map ( |inner| inner. iter ( ) ) . flat_map ( |inner| inner. iter ( ) ) {
527- mapping. add ( entry. clone ( ) ) ;
528- }
529- }
0 commit comments