@@ -24,6 +24,15 @@ public int TabWidth
24
24
set => SetValue ( TabWidthProperty , value ) ;
25
25
}
26
26
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
+
27
36
protected override Type StyleKeyOverride => typeof ( TextEditor ) ;
28
37
29
38
public RevisionTextFileView ( ) : base ( new TextArea ( ) , new TextDocument ( ) )
@@ -72,8 +81,8 @@ protected override void OnDataContextChanged(EventArgs e)
72
81
73
82
if ( DataContext is Models . RevisionTextFile source )
74
83
{
75
- UpdateTextMate ( ) ;
76
84
Text = source . Content ;
85
+ Models . TextMateHelper . SetGrammarByFileName ( _textMate , source . FileName ) ;
77
86
}
78
87
else
79
88
{
@@ -86,9 +95,9 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
86
95
base . OnPropertyChanged ( change ) ;
87
96
88
97
if ( change . Property == TabWidthProperty )
89
- {
90
98
Options . IndentationSize = TabWidth ;
91
- }
99
+ else if ( change . Property == UseSyntaxHighlightingProperty )
100
+ UpdateTextMate ( ) ;
92
101
}
93
102
94
103
private void OnTextViewContextRequested ( object sender , ContextRequestedEventArgs e )
@@ -124,11 +133,22 @@ private void OnTextViewContextRequested(object sender, ContextRequestedEventArgs
124
133
125
134
private void UpdateTextMate ( )
126
135
{
127
- if ( _textMate == null )
128
- _textMate = Models . TextMateHelper . CreateForEditor ( this ) ;
136
+ if ( UseSyntaxHighlighting )
137
+ {
138
+ if ( _textMate == null )
139
+ _textMate = Models . TextMateHelper . CreateForEditor ( this ) ;
129
140
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
+ }
132
152
}
133
153
134
154
private TextMate . Installation _textMate = null ;
0 commit comments