@@ -32,6 +32,56 @@ public MainWindowViewModel(IStorageProvider storageProvider, SettingsService set
3232 [ NotifyCanExecuteChangedFor ( nameof ( StartSearchCommand ) ) ]
3333 private string filePath = string . Empty ;
3434
35+ [ RelayCommand ]
36+ private async Task HandleFilePathLostFocusAsync ( )
37+ {
38+ if ( string . IsNullOrWhiteSpace ( FilePath ) || string . IsNullOrWhiteSpace ( WorkingDirectory ) )
39+ return ;
40+
41+ var processWrapper = new ProcessWrapper ( ) ;
42+ var absolutePath = Path . IsPathRooted ( FilePath )
43+ ? FilePath
44+ : Path . GetFullPath ( Path . Combine ( WorkingDirectory , FilePath ) ) ;
45+
46+ var result = await Task . Run ( ( ) =>
47+ processWrapper . Start ( "rev-parse --show-toplevel" , Path . GetDirectoryName ( absolutePath ) , null ) ) ;
48+
49+ if ( result . ExitCode == 0 )
50+ {
51+ var gitRoot = result . StandardOutput . Trim ( ) . Replace ( '/' , '\\ ' ) ; // Normalize to Windows path
52+
53+ await Avalonia . Threading . Dispatcher . UIThread . InvokeAsync ( ( ) =>
54+ {
55+ LogOutput . Add ( $ "Git Root: { gitRoot } ") ;
56+ LogOutput . Add ( $ "File Path: { absolutePath } ") ;
57+
58+ WorkingDirectory = gitRoot ;
59+
60+ // Convert paths to the same format and case for comparison
61+ if ( absolutePath . StartsWith ( gitRoot , StringComparison . OrdinalIgnoreCase ) )
62+ {
63+ var relativePath = absolutePath [ gitRoot . Length ..] . TrimStart ( '\\ ' , '/' ) ;
64+ FilePath = relativePath . Replace ( '\\ ' , '/' ) ;
65+ LogOutput . Add ( $ "Relative Path: { FilePath } ") ;
66+ }
67+ else
68+ {
69+ LogOutput . Add ( "Warning: File path does not start with git root path." ) ;
70+ FilePath = string . Empty ;
71+ }
72+ } ) ;
73+ }
74+ else
75+ {
76+ await Avalonia . Threading . Dispatcher . UIThread . InvokeAsync ( ( ) =>
77+ {
78+ LogOutput . Add ( "Warning: Selected file is not in a Git repository. Please select a file within a Git repository." ) ;
79+ FilePath = string . Empty ;
80+ WorkingDirectory = string . Empty ;
81+ } ) ;
82+ }
83+ }
84+
3585 [ ObservableProperty ]
3686 [ NotifyCanExecuteChangedFor ( nameof ( StartSearchCommand ) ) ]
3787 private string searchString = string . Empty ;
0 commit comments