@@ -759,17 +759,24 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
759759
760760 private async void OnTextAreaKeyDown ( object sender , KeyEventArgs e )
761761 {
762- if ( e . KeyModifiers . Equals ( OperatingSystem . IsMacOS ( ) ? KeyModifiers . Meta : KeyModifiers . Control ) )
762+ try
763763 {
764- if ( e . Key == Key . C )
764+ if ( e . KeyModifiers . Equals ( OperatingSystem . IsMacOS ( ) ? KeyModifiers . Meta : KeyModifiers . Control ) )
765765 {
766- await CopyWithoutIndicatorsAsync ( ) ;
767- e . Handled = true ;
766+ if ( e . Key == Key . C )
767+ {
768+ await CopyWithoutIndicatorsAsync ( ) ;
769+ e . Handled = true ;
770+ }
768771 }
769- }
770772
771- if ( ! e . Handled )
772- base . OnKeyDown ( e ) ;
773+ if ( ! e . Handled )
774+ base . OnKeyDown ( e ) ;
775+ }
776+ catch ( Exception ex )
777+ {
778+ App . RaiseException ( string . Empty , $ "Error in text area key handler: { ex . Message } ") ;
779+ }
773780 }
774781
775782 private void OnBlockNavigationPropertyChanged ( object _1 , PropertyChangedEventArgs e )
@@ -1816,55 +1823,74 @@ private void RefreshBlockNavigation()
18161823
18171824 private async void OnStageChunk ( object _1 , RoutedEventArgs _2 )
18181825 {
1819- var chunk = SelectedChunk ;
1820- if ( chunk == null )
1821- return ;
1822-
1823- var diff = DataContext as Models . TextDiff ;
1826+ try
1827+ {
1828+ var chunk = SelectedChunk ;
1829+ if ( chunk == null )
1830+ return ;
18241831
1825- var change = diff ? . Option . WorkingCopyChange ;
1826- if ( change == null )
1827- return ;
1832+ var diff = DataContext as Models . TextDiff ;
18281833
1829- var selection = diff . MakeSelection ( chunk . StartIdx + 1 , chunk . EndIdx + 1 , chunk . Combined , chunk . IsOldSide ) ;
1830- if ( ! selection . HasChanges )
1831- return ;
1834+ var change = diff ? . Option . WorkingCopyChange ;
1835+ if ( change == null )
1836+ return ;
18321837
1833- var repoView = this . FindAncestorOfType < Repository > ( ) ;
1838+ var selection = diff . MakeSelection ( chunk . StartIdx + 1 , chunk . EndIdx + 1 , chunk . Combined , chunk . IsOldSide ) ;
1839+ if ( ! selection . HasChanges )
1840+ return ;
18341841
1835- if ( repoView ? . DataContext is not ViewModels . Repository repo )
1836- return ;
1842+ var repoView = this . FindAncestorOfType < Repository > ( ) ;
18371843
1838- repo . SetWatcherEnabled ( false ) ;
1844+ if ( repoView ? . DataContext is not ViewModels . Repository repo )
1845+ return ;
18391846
1840- if ( ! selection . HasLeftChanges )
1841- {
1842- await new Commands . Add ( repo . FullPath , change ) . ExecAsync ( ) ;
1843- }
1844- else
1845- {
1846- var tmpFile = Path . GetTempFileName ( ) ;
1847- if ( change . WorkTree == Models . ChangeState . Untracked )
1848- {
1849- diff . GenerateNewPatchFromSelection ( change , null , selection , false , tmpFile ) ;
1850- }
1851- else if ( chunk . Combined )
1847+ repo . SetWatcherEnabled ( false ) ;
1848+ try
18521849 {
1853- var treeGuid = await new Commands . QueryStagedFileBlobGuid ( diff . Repo , change . Path ) . GetResultAsync ( ) ;
1854- diff . GeneratePatchFromSelection ( change , treeGuid , selection , false , tmpFile ) ;
1850+ if ( ! selection . HasLeftChanges )
1851+ {
1852+ await new Commands . Add ( repo . FullPath , change ) . ExecAsync ( ) ;
1853+ }
1854+ else
1855+ {
1856+ var tmpFile = Path . GetTempFileName ( ) ;
1857+ try
1858+ {
1859+ if ( change . WorkTree == Models . ChangeState . Untracked )
1860+ {
1861+ diff . GenerateNewPatchFromSelection ( change , null , selection , false , tmpFile ) ;
1862+ }
1863+ else if ( chunk . Combined )
1864+ {
1865+ var treeGuid = await new Commands . QueryStagedFileBlobGuid ( diff . Repo , change . Path ) . GetResultAsync ( ) ;
1866+ diff . GeneratePatchFromSelection ( change , treeGuid , selection , false , tmpFile ) ;
1867+ }
1868+ else
1869+ {
1870+ var treeGuid = await new Commands . QueryStagedFileBlobGuid ( diff . Repo , change . Path ) . GetResultAsync ( ) ;
1871+ diff . GeneratePatchFromSelectionSingleSide ( change , treeGuid , selection , false , chunk . IsOldSide , tmpFile ) ;
1872+ }
1873+
1874+ await new Commands . Apply ( diff . Repo , tmpFile , true , "nowarn" , "--cache --index" ) . ExecAsync ( ) ;
1875+ }
1876+ finally
1877+ {
1878+ if ( File . Exists ( tmpFile ) )
1879+ File . Delete ( tmpFile ) ;
1880+ }
1881+ }
1882+
1883+ repo . MarkWorkingCopyDirtyManually ( ) ;
18551884 }
1856- else
1885+ finally
18571886 {
1858- var treeGuid = await new Commands . QueryStagedFileBlobGuid ( diff . Repo , change . Path ) . GetResultAsync ( ) ;
1859- diff . GeneratePatchFromSelectionSingleSide ( change , treeGuid , selection , false , chunk . IsOldSide , tmpFile ) ;
1887+ repo . SetWatcherEnabled ( true ) ;
18601888 }
1861-
1862- await new Commands . Apply ( diff . Repo , tmpFile , true , "nowarn" , "--cache --index" ) . ExecAsync ( ) ;
1863- File . Delete ( tmpFile ) ;
18641889 }
1865-
1866- repo . MarkWorkingCopyDirtyManually ( ) ;
1867- repo . SetWatcherEnabled ( true ) ;
1890+ catch ( Exception ex )
1891+ {
1892+ App . RaiseException ( string . Empty , $ "Error staging chunk: { ex . Message } ") ;
1893+ }
18681894 }
18691895
18701896 private async void OnUnstageChunk ( object _1 , RoutedEventArgs _2 )
0 commit comments