@@ -17,16 +17,19 @@ 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+ // TODO: Fix this failing to load the correct data (and throwing a console warning) because it's occurring before the value has been supplied during initialization from the JS `initAfterFrontendReady`
31+ let keyboard_platform = GLOBAL_PLATFORM . get ( ) . copied ( ) . unwrap_or_default ( ) . as_keyboard_platform_layout ( ) ;
32+
3033 // NOTICE:
3134 // If a new mapping you added here isn't working (and perhaps another lower-precedence one is instead), make sure to advertise
3235 // it as an available action in the respective message handler file (such as the bottom of `document_message_handler.rs`).
@@ -54,6 +57,11 @@ pub fn input_mappings() -> Mapping {
5457 // Hack to prevent Left Click + Accel + Z combo (this effectively blocks you from making a double undo with AbortTransaction)
5558 entry!( KeyDown ( KeyZ ) ; modifiers=[ Accel , MouseLeft ] , action_dispatch=DocumentMessage :: Noop ) ,
5659 //
60+ // AppWindowMessage
61+ entry!( KeyDown ( F11 ) ; disabled=( keyboard_platform == KeyboardPlatformLayout :: Mac ) , action_dispatch=AppWindowMessage :: Fullscreen ) ,
62+ entry!( KeyDown ( KeyF ) ; modifiers=[ Command , Control ] , disabled=( keyboard_platform != KeyboardPlatformLayout :: Mac ) , action_dispatch=AppWindowMessage :: Fullscreen ) ,
63+ entry!( KeyDown ( KeyQ ) ; modifiers=[ Command ] , disabled=cfg!( not( target_os = "macos" ) ) , action_dispatch=AppWindowMessage :: Close ) ,
64+ //
5765 // ClipboardMessage
5866 entry!( KeyDown ( KeyX ) ; modifiers=[ Accel ] , action_dispatch=ClipboardMessage :: Cut ) ,
5967 entry!( KeyDown ( KeyC ) ; modifiers=[ Accel ] , action_dispatch=ClipboardMessage :: Copy ) ,
@@ -416,10 +424,14 @@ pub fn input_mappings() -> Mapping {
416424 entry!( KeyDown ( FakeKeyPlus ) ; modifiers=[ Accel ] , canonical, action_dispatch=NavigationMessage :: CanvasZoomIncrease { center_on_mouse: false } ) ,
417425 entry!( KeyDown ( Equal ) ; modifiers=[ Accel ] , action_dispatch=NavigationMessage :: CanvasZoomIncrease { center_on_mouse: false } ) ,
418426 entry!( KeyDown ( Minus ) ; modifiers=[ Accel ] , action_dispatch=NavigationMessage :: CanvasZoomDecrease { center_on_mouse: false } ) ,
419- entry!( WheelScroll ; modifiers=[ Control ] , action_dispatch=NavigationMessage :: CanvasZoomMouseWheel ) ,
420- entry!( WheelScroll ; modifiers=[ Command ] , action_dispatch=NavigationMessage :: CanvasZoomMouseWheel ) ,
421- entry!( WheelScroll ; modifiers=[ Shift ] , action_dispatch=NavigationMessage :: CanvasPanMouseWheel { use_y_as_x: true } ) ,
422- entry!( WheelScroll ; action_dispatch=NavigationMessage :: CanvasPanMouseWheel { use_y_as_x: false } ) ,
427+ entry!( WheelScroll ; modifiers=[ Control ] , disabled=zoom_with_scroll, action_dispatch=NavigationMessage :: CanvasZoomMouseWheel ) ,
428+ entry!( WheelScroll ; modifiers=[ Command ] , disabled=zoom_with_scroll, action_dispatch=NavigationMessage :: CanvasZoomMouseWheel ) ,
429+ entry!( WheelScroll ; modifiers=[ Shift ] , disabled=zoom_with_scroll, action_dispatch=NavigationMessage :: CanvasPanMouseWheel { use_y_as_x: true } ) ,
430+ entry!( WheelScroll ; disabled=zoom_with_scroll, action_dispatch=NavigationMessage :: CanvasPanMouseWheel { use_y_as_x: false } ) ,
431+ // 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
432+ entry!( WheelScroll ; modifiers=[ Control ] , disabled=!zoom_with_scroll, action_dispatch=NavigationMessage :: CanvasPanMouseWheel { use_y_as_x: keyboard_platform == KeyboardPlatformLayout :: Mac } ) ,
433+ entry!( WheelScroll ; modifiers=[ Shift ] , disabled=!zoom_with_scroll, action_dispatch=NavigationMessage :: CanvasPanMouseWheel { use_y_as_x: keyboard_platform != KeyboardPlatformLayout :: Mac } ) ,
434+ entry!( WheelScroll ; disabled=!zoom_with_scroll, action_dispatch=NavigationMessage :: CanvasZoomMouseWheel ) ,
423435 entry!( KeyDown ( PageUp ) ; modifiers=[ Shift ] , action_dispatch=NavigationMessage :: CanvasPanByViewportFraction { delta: DVec2 :: new( 1. , 0. ) } ) ,
424436 entry!( KeyDown ( PageDown ) ; modifiers=[ Shift ] , action_dispatch=NavigationMessage :: CanvasPanByViewportFraction { delta: DVec2 :: new( -1. , 0. ) } ) ,
425437 entry!( KeyDown ( PageUp ) ; action_dispatch=NavigationMessage :: CanvasPanByViewportFraction { delta: DVec2 :: new( 0. , 1. ) } ) ,
@@ -471,7 +483,7 @@ pub fn input_mappings() -> Mapping {
471483 // Sort `pointer_shake`
472484 sort ( & mut pointer_shake) ;
473485
474- let mut mapping = Mapping {
486+ Mapping {
475487 key_up,
476488 key_down,
477489 key_up_no_repeat,
@@ -480,54 +492,5 @@ pub fn input_mappings() -> Mapping {
480492 wheel_scroll,
481493 pointer_move,
482494 pointer_shake,
483- } ;
484-
485- if cfg ! ( target_os = "macos" ) {
486- let remove: [ & [ & [ MappingEntry ; 0 ] ; 0 ] ; 0 ] = [ ] ;
487- let add = [ entry ! ( KeyDown ( KeyQ ) ; modifiers=[ Accel ] , action_dispatch=AppWindowMessage :: Close ) ] ;
488-
489- apply_mapping_patch ( & mut mapping, remove, add) ;
490- }
491-
492- mapping
493- }
494-
495- /// Default mappings except that scrolling without modifier keys held down is bound to zooming instead of vertical panning
496- pub fn zoom_with_scroll ( ) -> Mapping {
497- use InputMapperMessage :: * ;
498-
499- // 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
500- let keyboard_platform = GLOBAL_PLATFORM . get ( ) . copied ( ) . unwrap_or_default ( ) . as_keyboard_platform_layout ( ) ;
501-
502- let mut mapping = input_mappings ( ) ;
503-
504- let remove = [
505- entry ! ( WheelScroll ; modifiers=[ Control ] , action_dispatch=NavigationMessage :: CanvasZoomMouseWheel ) ,
506- entry ! ( WheelScroll ; modifiers=[ Command ] , action_dispatch=NavigationMessage :: CanvasZoomMouseWheel ) ,
507- entry ! ( WheelScroll ; modifiers=[ Shift ] , action_dispatch=NavigationMessage :: CanvasPanMouseWheel { use_y_as_x: true } ) ,
508- entry ! ( WheelScroll ; action_dispatch=NavigationMessage :: CanvasPanMouseWheel { use_y_as_x: false } ) ,
509- ] ;
510- let add = [
511- entry ! ( WheelScroll ; modifiers=[ Control ] , action_dispatch=NavigationMessage :: CanvasPanMouseWheel { use_y_as_x: keyboard_platform == KeyboardPlatformLayout :: Mac } ) ,
512- entry ! ( WheelScroll ; modifiers=[ Shift ] , action_dispatch=NavigationMessage :: CanvasPanMouseWheel { use_y_as_x: keyboard_platform != KeyboardPlatformLayout :: Mac } ) ,
513- entry ! ( WheelScroll ; action_dispatch=NavigationMessage :: CanvasZoomMouseWheel ) ,
514- ] ;
515-
516- apply_mapping_patch ( & mut mapping, remove, add) ;
517-
518- mapping
519- }
520-
521- fn apply_mapping_patch < ' a , const N : usize , const M : usize , const X : usize , const Y : usize > (
522- mapping : & mut Mapping ,
523- remove : impl IntoIterator < Item = & ' a [ & ' a [ MappingEntry ; N ] ; M ] > ,
524- add : impl IntoIterator < Item = & ' a [ & ' a [ MappingEntry ; X ] ; Y ] > ,
525- ) {
526- for entry in remove. into_iter ( ) . flat_map ( |inner| inner. iter ( ) ) . flat_map ( |inner| inner. iter ( ) ) {
527- mapping. remove ( entry) ;
528- }
529-
530- for entry in add. into_iter ( ) . flat_map ( |inner| inner. iter ( ) ) . flat_map ( |inner| inner. iter ( ) ) {
531- mapping. add ( entry. clone ( ) ) ;
532495 }
533496}
0 commit comments