@@ -24,6 +24,15 @@ public int TabWidth
2424 set => SetValue ( TabWidthProperty , value ) ;
2525 }
2626
27+ public static readonly StyledProperty < bool > UseSyntaxHighlightingProperty =
28+ AvaloniaProperty . Register < RevisionTextFileView , bool > ( nameof ( UseSyntaxHighlighting ) ) ;
29+
30+ public bool UseSyntaxHighlighting
31+ {
32+ get => GetValue ( UseSyntaxHighlightingProperty ) ;
33+ set => SetValue ( UseSyntaxHighlightingProperty , value ) ;
34+ }
35+
2736 protected override Type StyleKeyOverride => typeof ( TextEditor ) ;
2837
2938 public RevisionTextFileView ( ) : base ( new TextArea ( ) , new TextDocument ( ) )
@@ -72,8 +81,8 @@ protected override void OnDataContextChanged(EventArgs e)
7281
7382 if ( DataContext is Models . RevisionTextFile source )
7483 {
75- UpdateTextMate ( ) ;
7684 Text = source . Content ;
85+ Models . TextMateHelper . SetGrammarByFileName ( _textMate , source . FileName ) ;
7786 }
7887 else
7988 {
@@ -86,9 +95,9 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
8695 base . OnPropertyChanged ( change ) ;
8796
8897 if ( change . Property == TabWidthProperty )
89- {
9098 Options . IndentationSize = TabWidth ;
91- }
99+ else if ( change . Property == UseSyntaxHighlightingProperty )
100+ UpdateTextMate ( ) ;
92101 }
93102
94103 private void OnTextViewContextRequested ( object sender , ContextRequestedEventArgs e )
@@ -124,11 +133,22 @@ private void OnTextViewContextRequested(object sender, ContextRequestedEventArgs
124133
125134 private void UpdateTextMate ( )
126135 {
127- if ( _textMate == null )
128- _textMate = Models . TextMateHelper . CreateForEditor ( this ) ;
136+ if ( UseSyntaxHighlighting )
137+ {
138+ if ( _textMate == null )
139+ _textMate = Models . TextMateHelper . CreateForEditor ( this ) ;
129140
130- if ( DataContext is Models . RevisionTextFile file )
131- Models . TextMateHelper . SetGrammarByFileName ( _textMate , file . FileName ) ;
141+ if ( DataContext is Models . RevisionTextFile file )
142+ Models . TextMateHelper . SetGrammarByFileName ( _textMate , file . FileName ) ;
143+ }
144+ else if ( _textMate != null )
145+ {
146+ _textMate . Dispose ( ) ;
147+ _textMate = null ;
148+ GC . Collect ( ) ;
149+
150+ TextArea . TextView . Redraw ( ) ;
151+ }
132152 }
133153
134154 private TextMate . Installation _textMate = null ;
0 commit comments