Skip to content

Commit 1b58989

Browse files
authored
Minor cleanup
Member textArea in TextEditor is readonly and set in ctors - it's never null. No need for null checks or access via the public property.
1 parent e67b6c6 commit 1b58989

1 file changed

Lines changed: 14 additions & 34 deletions

File tree

ICSharpCode.AvalonEdit/TextEditor.cs

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
9797
{
9898
base.OnGotKeyboardFocus(e);
9999
if (e.NewFocus == this) {
100-
Keyboard.Focus(this.TextArea);
100+
Keyboard.Focus(textArea);
101101
e.Handled = true;
102102
}
103103
}
@@ -299,18 +299,12 @@ internal ScrollViewer ScrollViewer {
299299

300300
bool CanExecute(RoutedUICommand command)
301301
{
302-
TextArea textArea = this.TextArea;
303-
if (textArea == null)
304-
return false;
305-
else
306-
return command.CanExecute(null, textArea);
302+
return command.CanExecute(null, textArea);
307303
}
308304

309305
void Execute(RoutedUICommand command)
310306
{
311-
TextArea textArea = this.TextArea;
312-
if (textArea != null)
313-
command.Execute(null, textArea);
307+
command.Execute(null, textArea);
314308
}
315309
#endregion
316310

@@ -341,13 +335,13 @@ static void OnSyntaxHighlightingChanged(DependencyObject d, DependencyPropertyCh
341335
void OnSyntaxHighlightingChanged(IHighlightingDefinition newValue)
342336
{
343337
if (colorizer != null) {
344-
this.TextArea.TextView.LineTransformers.Remove(colorizer);
338+
textArea.TextView.LineTransformers.Remove(colorizer);
345339
colorizer = null;
346340
}
347341
if (newValue != null) {
348342
colorizer = CreateColorizer(newValue);
349343
if (colorizer != null)
350-
this.TextArea.TextView.LineTransformers.Insert(0, colorizer);
344+
textArea.TextView.LineTransformers.Insert(0, colorizer);
351345
}
352346
}
353347

@@ -825,19 +819,17 @@ public double HorizontalOffset {
825819
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
826820
public string SelectedText {
827821
get {
828-
TextArea textArea = this.TextArea;
829822
// We'll get the text from the whole surrounding segment.
830823
// This is done to ensure that SelectedText.Length == SelectionLength.
831-
if (textArea != null && textArea.Document != null && !textArea.Selection.IsEmpty)
824+
if (textArea.Document != null && !textArea.Selection.IsEmpty)
832825
return textArea.Document.GetText(textArea.Selection.SurroundingSegment);
833826
else
834827
return string.Empty;
835828
}
836829
set {
837830
if (value == null)
838831
throw new ArgumentNullException("value");
839-
TextArea textArea = this.TextArea;
840-
if (textArea != null && textArea.Document != null) {
832+
if (textArea.Document != null) {
841833
int offset = this.SelectionStart;
842834
int length = this.SelectionLength;
843835
textArea.Document.Replace(offset, length, value);
@@ -853,16 +845,10 @@ public string SelectedText {
853845
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
854846
public int CaretOffset {
855847
get {
856-
TextArea textArea = this.TextArea;
857-
if (textArea != null)
858-
return textArea.Caret.Offset;
859-
else
860-
return 0;
848+
return textArea.Caret.Offset;
861849
}
862850
set {
863-
TextArea textArea = this.TextArea;
864-
if (textArea != null)
865-
textArea.Caret.Offset = value;
851+
textArea.Caret.Offset = value;
866852
}
867853
}
868854

@@ -872,15 +858,10 @@ public int CaretOffset {
872858
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
873859
public int SelectionStart {
874860
get {
875-
TextArea textArea = this.TextArea;
876-
if (textArea != null) {
877-
if (textArea.Selection.IsEmpty)
878-
return textArea.Caret.Offset;
879-
else
880-
return textArea.Selection.SurroundingSegment.Offset;
881-
} else {
882-
return 0;
883-
}
861+
if (textArea.Selection.IsEmpty)
862+
return textArea.Caret.Offset;
863+
else
864+
return textArea.Selection.SurroundingSegment.Offset;
884865
}
885866
set {
886867
Select(value, SelectionLength);
@@ -893,8 +874,7 @@ public int SelectionStart {
893874
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
894875
public int SelectionLength {
895876
get {
896-
TextArea textArea = this.TextArea;
897-
if (textArea != null && !textArea.Selection.IsEmpty)
877+
if (!textArea.Selection.IsEmpty)
898878
return textArea.Selection.SurroundingSegment.Length;
899879
else
900880
return 0;

0 commit comments

Comments
 (0)