Skip to content

Commit da00e5d

Browse files
authored
Using Command instead of Control on MacOS and fixed Shift key behaviour (#76)
About Shift key behaviour: the Shift clicked file was being added to the front of the selected files list whereas it should've been added to the end of the list, that's now fixed
1 parent 1e8a795 commit da00e5d

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//#define WIN_DIR_CHECK_WITHOUT_TIMEOUT // When uncommented, Directory.Exists won't be wrapped inside a Task/Thread on Windows but we won't be able to set a timeout for unreachable directories/drives
1+
//#define WIN_DIR_CHECK_WITHOUT_TIMEOUT // When uncommented, Directory.Exists won't be wrapped inside a Task/Thread on Windows but we won't be able to set a timeout for unreachable directories/drives
22

33
using UnityEngine;
44
using UnityEngine.EventSystems;
@@ -940,9 +940,9 @@ private void LateUpdate()
940940
RenameSelectedFile();
941941

942942
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
943-
if( Keyboard.current[Key.A].wasPressedThisFrame && Keyboard.current.ctrlKey.isPressed )
943+
if( Keyboard.current[Key.A].wasPressedThisFrame && IsCtrlKeyHeld() )
944944
#else
945-
if( Input.GetKeyDown( KeyCode.A ) && ( Input.GetKey( KeyCode.LeftControl ) || Input.GetKey( KeyCode.LeftCommand ) ) )
945+
if( Input.GetKeyDown( KeyCode.A ) && IsCtrlKeyHeld() )
946946
#endif
947947
SelectAllFiles();
948948
}
@@ -1771,26 +1771,23 @@ public void OnItemSelected( FileBrowserItem item, bool isDoubleClick )
17711771
multiSelectionPivotFileEntry = Mathf.Clamp( multiSelectionPivotFileEntry, 0, validFileEntries.Count - 1 );
17721772

17731773
selectedFileEntries.Clear();
1774-
selectedFileEntries.Add( item.Position );
17751774

17761775
for( int i = multiSelectionPivotFileEntry; i < item.Position; i++ )
17771776
selectedFileEntries.Add( i );
17781777

17791778
for( int i = multiSelectionPivotFileEntry; i > item.Position; i-- )
17801779
selectedFileEntries.Add( i );
1780+
1781+
selectedFileEntries.Add( item.Position );
17811782
}
17821783
else
17831784
#endif
17841785
{
17851786
multiSelectionPivotFileEntry = item.Position;
17861787

1787-
// When in toggle selection mode or Control key is held, individual items can be multi-selected
1788+
// When in toggle selection mode or Control/Command key is held, individual items can be multi-selected
17881789
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBGL || UNITY_WSA || UNITY_WSA_10_0
1789-
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
1790-
if( m_multiSelectionToggleSelectionMode || ( Keyboard.current != null && Keyboard.current.ctrlKey.isPressed ) )
1791-
#else
1792-
if( m_multiSelectionToggleSelectionMode || Input.GetKey( KeyCode.LeftControl ) || Input.GetKey( KeyCode.RightControl ) )
1793-
#endif
1790+
if( m_multiSelectionToggleSelectionMode || IsCtrlKeyHeld() )
17941791
#else
17951792
if( m_multiSelectionToggleSelectionMode )
17961793
#endif
@@ -2164,7 +2161,7 @@ public void SelectAllFiles()
21642161
// Don't select folders in file picking mode if MultiSelectionToggleSelectionMode is enabled or about to be enabled
21652162
for( int i = 0; i < validFileEntries.Count; i++ )
21662163
{
2167-
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WSA || UNITY_WSA_10_0
2164+
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBGL || UNITY_WSA || UNITY_WSA_10_0
21682165
if( !m_multiSelectionToggleSelectionMode || !validFileEntries[i].IsDirectory )
21692166
#else
21702167
if( !validFileEntries[i].IsDirectory )
@@ -2834,6 +2831,24 @@ private bool CheckDirectoryWriteAccess( string path )
28342831
catch { }
28352832
}
28362833
}
2834+
2835+
// Check if Control/Command key is held
2836+
private bool IsCtrlKeyHeld()
2837+
{
2838+
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
2839+
#if UNITY_EDITOR_OSX || ( !UNITY_EDITOR && UNITY_STANDALONE_OSX )
2840+
return Keyboard.current != null && ( Keyboard.current.leftCommandKey.isPressed || Keyboard.current.rightCommandKey.isPressed );
2841+
#else
2842+
return Keyboard.current != null && Keyboard.current.ctrlKey.isPressed;
2843+
#endif
2844+
#else
2845+
#if UNITY_EDITOR_OSX || ( !UNITY_EDITOR && UNITY_STANDALONE_OSX )
2846+
return Input.GetKey( KeyCode.LeftCommand ) || Input.GetKey( KeyCode.RightCommand );
2847+
#else
2848+
return Input.GetKey( KeyCode.LeftControl ) || Input.GetKey( KeyCode.RightControl );
2849+
#endif
2850+
#endif
2851+
}
28372852
#endregion
28382853

28392854
#region File Browser Functions (static)
@@ -3128,4 +3143,4 @@ public static Permission RequestPermission()
31283143
}
31293144
#endregion
31303145
}
3131-
}
3146+
}

0 commit comments

Comments
 (0)