Skip to content

Commit

Permalink
Use null coalescing operator
Browse files Browse the repository at this point in the history
  • Loading branch information
drewnoakes committed Jul 5, 2018
1 parent da6c810 commit 5d5ab63
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project/Src/Document/DefaultDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public int PositionToOffset(TextLocation p)
public void UpdateSegmentListOnDocumentChange<T>(List<T> list, DocumentEventArgs e) where T : ISegment
{
var removedCharacters = e.Length > 0 ? e.Length : 0;
var insertedCharacters = e.Text != null ? e.Text.Length : 0;
var insertedCharacters = e.Text?.Length ?? 0;
for (var i = 0; i < list.Count; ++i)
{
ISegment s = list[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -741,11 +741,11 @@ private void PushCurWord(IDocument document, ref HighlightColor markNext, List<T
hasDefaultColor = true;
}

words.Add(new TextWord(document, currentLine, currentOffset, currentLength, markNext != null ? markNext : c, hasDefaultColor));
words.Add(new TextWord(document, currentLine, currentOffset, currentLength, markNext ?? c, hasDefaultColor));
}
else
{
var c = markNext != null ? markNext : GetColor(activeRuleSet, document, currentLine, currentOffset, currentLength);
var c = markNext ?? GetColor(activeRuleSet, document, currentLine, currentOffset, currentLength);
if (c == null)
words.Add(new TextWord(document, currentLine, currentOffset, currentLength, DefaultTextColor, hasDefaultColor: true));
else
Expand Down
2 changes: 1 addition & 1 deletion Project/Src/Document/HighlightingStrategy/Span.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public HighlightColor BeginColor
}
}

public HighlightColor EndColor => endColor != null ? endColor : Color;
public HighlightColor EndColor => endColor ?? Color;

public char[] Begin { get; }

Expand Down
4 changes: 2 additions & 2 deletions Project/Src/Document/LineManager/LineSegmentTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private RedBlackTreeNode<RBNode> GetNode(int index)

private static int GetIndexFromNode(RedBlackTreeNode<RBNode> node)
{
var index = node.left != null ? node.left.val.count : 0;
var index = node.left?.val.count ?? 0;
while (node.parent != null)
{
if (node == node.parent.right)
Expand Down Expand Up @@ -210,7 +210,7 @@ private RedBlackTreeNode<RBNode> GetNodeByOffset(int offset)

private static int GetOffsetFromNode(RedBlackTreeNode<RBNode> node)
{
var offset = node.left != null ? node.left.val.totalLength : 0;
var offset = node.left?.val.totalLength ?? 0;
while (node.parent != null)
{
if (node == node.parent.right)
Expand Down
2 changes: 1 addition & 1 deletion Project/Src/Gui/TextView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ internal TextLocation GetLogicalColumn(int lineNumber, int visualPosX, out FoldM
{
var line = Document.GetLineSegment(lineNumber);
var nextFolding = FindNextFoldedFoldingOnLineAfterColumn(lineNumber, start - 1);
var end = nextFolding != null ? nextFolding.StartColumn : int.MaxValue;
var end = nextFolding?.StartColumn ?? int.MaxValue;
result = GetLogicalColumnInternal(g, line, start, end, ref posX, visualPosX);

// break when GetLogicalColumnInternal found the result column
Expand Down
2 changes: 1 addition & 1 deletion Project/Src/Util/AugmentableRedBlackTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ private static RedBlackTreeNode<T> Sibling(RedBlackTreeNode<T> node, RedBlackTre

private static bool GetColor(RedBlackTreeNode<T> node)
{
return node != null ? node.color : BLACK;
return node != null && node.color;
}

private void FixTreeOnDelete(RedBlackTreeNode<T> node, RedBlackTreeNode<T> parentNode)
Expand Down

0 comments on commit 5d5ab63

Please sign in to comment.