Skip to content

Commit

Permalink
Merge pull request #367 from X-Sharp/master
Browse files Browse the repository at this point in the history
Remove Sameword Highlights when the cursor moves to a whitespace area
  • Loading branch information
madskristensen authored Aug 1, 2022
2 parents f5d1789 + 9e2ed6a commit fe656dc
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,20 @@ private void CaretPositionChanged(object sender, CaretPositionChangedEventArgs e
UpdateAtCaretPosition(e.NewPosition);
}

private void ClearSpans()
{
lock (_syncLock)
{
_currentWord = null;
_wordSpans = new();
SnapshotSpan span = new(_buffer.CurrentSnapshot, 0, _buffer.CurrentSnapshot.Length);
TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(span));
}
}
private void UpdateAtCaretPosition(CaretPosition caretPosition)
{
SnapshotPoint? point = caretPosition.Point.GetPoint(_buffer, caretPosition.Affinity);

if (!point.HasValue)
{
return;
Expand All @@ -117,6 +127,13 @@ private void UpdateAtCaretPosition(CaretPosition caretPosition)
UpdateWordAdornments(word.Value);
}, VsTaskRunContext.UIThreadIdlePriority).FireAndForget();
}
else
{
// Clear the spans, to make sure that the highlights are
// removed when we move the caret to whitespace
ClearSpans();
}

}

private void UpdateWordAdornments(TextExtent word)
Expand Down

0 comments on commit fe656dc

Please sign in to comment.