@@ -669,6 +669,8 @@ protected override void OnLoaded(RoutedEventArgs e)
669
669
TextArea . TextView . PointerWheelChanged += OnTextViewPointerWheelChanged ;
670
670
TextArea . TextView . VisualLinesChanged += OnTextViewVisualLinesChanged ;
671
671
672
+ TextArea . AddHandler ( KeyDownEvent , OnTextAreaKeyDown , RoutingStrategies . Tunnel ) ;
673
+
672
674
UpdateTextMate ( ) ;
673
675
OnTextViewVisualLinesChanged ( null , null ) ;
674
676
}
@@ -677,6 +679,8 @@ protected override void OnUnloaded(RoutedEventArgs e)
677
679
{
678
680
base . OnUnloaded ( e ) ;
679
681
682
+ TextArea . RemoveHandler ( KeyDownEvent , OnTextAreaKeyDown ) ;
683
+
680
684
TextArea . TextView . ContextRequested -= OnTextViewContextRequested ;
681
685
TextArea . TextView . PointerEntered -= OnTextViewPointerChanged ;
682
686
TextArea . TextView . PointerMoved -= OnTextViewPointerChanged ;
@@ -732,6 +736,21 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
732
736
}
733
737
}
734
738
739
+ private void OnTextAreaKeyDown ( object sender , KeyEventArgs e )
740
+ {
741
+ if ( e . KeyModifiers . Equals ( OperatingSystem . IsMacOS ( ) ? KeyModifiers . Meta : KeyModifiers . Control ) )
742
+ {
743
+ if ( e . Key == Key . C )
744
+ {
745
+ CopyWithoutIndicators ( ) ;
746
+ e . Handled = true ;
747
+ }
748
+ }
749
+
750
+ if ( ! e . Handled )
751
+ base . OnKeyDown ( e ) ;
752
+ }
753
+
735
754
private void OnBlockNavigationPropertyChanged ( object _1 , PropertyChangedEventArgs _2 )
736
755
{
737
756
TextArea ? . TextView ? . Redraw ( ) ;
@@ -748,7 +767,7 @@ private void OnTextViewContextRequested(object sender, ContextRequestedEventArgs
748
767
copy . Icon = App . CreateMenuIcon ( "Icons.Copy" ) ;
749
768
copy . Click += ( _ , ev ) =>
750
769
{
751
- App . CopyText ( SelectedText ) ;
770
+ CopyWithoutIndicators ( ) ;
752
771
ev . Handled = true ;
753
772
} ;
754
773
@@ -941,6 +960,59 @@ private void UpdateTextMate()
941
960
}
942
961
}
943
962
963
+ private void CopyWithoutIndicators ( )
964
+ {
965
+ var selection = TextArea . Selection ;
966
+ if ( selection . IsEmpty )
967
+ {
968
+ App . CopyText ( string . Empty ) ;
969
+ return ;
970
+ }
971
+
972
+ var lines = GetLines ( ) ;
973
+ var startIdx = Math . Min ( selection . StartPosition . Line - 1 , lines . Count - 1 ) ;
974
+ var endIdx = Math . Min ( selection . EndPosition . Line - 1 , lines . Count - 1 ) ;
975
+
976
+ if ( startIdx == endIdx )
977
+ {
978
+ var line = lines [ startIdx ] ;
979
+ if ( line . Type == Models . TextDiffLineType . Indicator ||
980
+ line . Type == Models . TextDiffLineType . None )
981
+ {
982
+ App . CopyText ( string . Empty ) ;
983
+ return ;
984
+ }
985
+
986
+ App . CopyText ( SelectedText ) ;
987
+ return ;
988
+ }
989
+
990
+ var builder = new StringBuilder ( ) ;
991
+ for ( var i = startIdx ; i <= endIdx ; i ++ )
992
+ {
993
+ var line = lines [ i ] ;
994
+ if ( line . Type == Models . TextDiffLineType . Indicator ||
995
+ line . Type == Models . TextDiffLineType . None )
996
+ continue ;
997
+
998
+ if ( i == startIdx && selection . StartPosition . Column > 1 )
999
+ {
1000
+ builder . AppendLine ( line . Content . Substring ( selection . StartPosition . Column - 1 ) ) ;
1001
+ continue ;
1002
+ }
1003
+
1004
+ if ( i == endIdx && selection . EndPosition . Column < line . Content . Length )
1005
+ {
1006
+ builder . AppendLine ( line . Content . Substring ( 0 , selection . EndPosition . Column ) ) ;
1007
+ continue ;
1008
+ }
1009
+
1010
+ builder . AppendLine ( line . Content ) ;
1011
+ }
1012
+
1013
+ App . CopyText ( builder . ToString ( ) ) ;
1014
+ }
1015
+
944
1016
private TextMate . Installation _textMate = null ;
945
1017
private TextLocation _lastSelectStart = TextLocation . Empty ;
946
1018
private TextLocation _lastSelectEnd = TextLocation . Empty ;
0 commit comments