@@ -698,24 +698,25 @@ private static bool TryGetNotoFont(string langKey, out string notoFont)
698698
699699 private static readonly InputSimulator _inputSimulator = new ( ) ;
700700
701- internal static bool FileJump ( string filePath , HWND dialogHandle , bool altD = true )
701+ internal static bool FileJump ( string filePath , HWND dialogHandle , bool forceFileName = false , bool altD = true )
702702 {
703- return DirFileJump ( Path . GetDirectoryName ( filePath ) , filePath , dialogHandle , altD ) ;
703+ if ( forceFileName )
704+ {
705+ return DirFileJumpForFileName ( filePath , dialogHandle ) ;
706+ }
707+ else
708+ {
709+ return DirFileJump ( Path . GetDirectoryName ( filePath ) , filePath , dialogHandle , altD ) ;
710+ }
704711 }
705712
706713 internal static bool DirJump ( string dirPath , HWND dialogHandle , bool altD = true )
707714 {
708715 return DirFileJump ( dirPath , null , dialogHandle , altD ) ;
709716 }
710717
711- private static unsafe bool DirFileJump ( string dirPath , string filePath , HWND dialogHandle , bool altD = true , bool editFileName = false )
718+ private static unsafe bool DirFileJump ( string dirPath , string filePath , HWND dialogHandle , bool altD = true )
712719 {
713- // Directly edit file name input box.
714- if ( editFileName )
715- {
716- return DirFileJumpForFileName ( filePath , dialogHandle ) ;
717- }
718-
719720 // Alt-D or Ctrl-L to focus on the path input box
720721 if ( altD )
721722 {
@@ -752,7 +753,7 @@ private static unsafe bool DirFileJump(string dirPath, string filePath, HWND dia
752753 {
753754 // https://github.com/idkidknow/Flow.Launcher.Plugin.DirQuickJump/issues/1
754755 // The dialog is a legacy one, so we edit file name text box directly.
755- return DirFileJumpForFileName ( string . IsNullOrEmpty ( filePath ) ? dirPath : filePath , dialogHandle ) ;
756+ return DirFileJumpForFileName ( string . IsNullOrEmpty ( filePath ) ? dirPath : filePath , dialogHandle , true ) ;
756757 }
757758
758759 var timeOut = ! SpinWait . SpinUntil ( ( ) =>
@@ -784,7 +785,7 @@ private static unsafe bool DirFileJump(string dirPath, string filePath, HWND dia
784785 if ( ! string . IsNullOrEmpty ( filePath ) )
785786 {
786787 // After navigating to the path, we then set the file name.
787- return DirFileJump ( null , Path . GetFileName ( filePath ) , dialogHandle , altD , true ) ;
788+ return DirFileJumpForFileName ( Path . GetFileName ( filePath ) , dialogHandle , true ) ;
788789 }
789790
790791 return true ;
@@ -793,7 +794,7 @@ private static unsafe bool DirFileJump(string dirPath, string filePath, HWND dia
793794 /// <summary>
794795 /// Edit file name text box in the file open dialog.
795796 /// </summary>
796- private static bool DirFileJumpForFileName ( string fileName , HWND dialogHandle )
797+ private static bool DirFileJumpForFileName ( string fileName , HWND dialogHandle , bool openTwice = false )
797798 {
798799 var controlHandle = PInvoke . FindWindowEx ( dialogHandle , HWND . Null , "ComboBoxEx32" , null ) ;
799800 controlHandle = PInvoke . FindWindowEx ( controlHandle , HWND . Null , "ComboBox" , null ) ;
@@ -811,10 +812,13 @@ private static bool DirFileJumpForFileName(string fileName, HWND dialogHandle)
811812
812813 SetWindowText ( controlHandle , fileName ) ;
813814
814- // Alt-O (equivalent to press the Open button) twice. In normal cases it suffices to press once,
815- // but when the focus is on an irrelevant folder, that press once will just open the irrelevant one.
816- _inputSimulator . Keyboard . ModifiedKeyStroke ( VirtualKeyCode . LMENU , VirtualKeyCode . VK_O ) ;
817815 _inputSimulator . Keyboard . ModifiedKeyStroke ( VirtualKeyCode . LMENU , VirtualKeyCode . VK_O ) ;
816+ if ( openTwice )
817+ {
818+ // Alt-O (equivalent to press the Open button) twice. In normal cases it suffices to press once,
819+ // but when the focus is on an irrelevant folder, that press once will just open the irrelevant one.
820+ _inputSimulator . Keyboard . ModifiedKeyStroke ( VirtualKeyCode . LMENU , VirtualKeyCode . VK_O ) ;
821+ }
818822
819823 return true ;
820824 }
0 commit comments