Skip to content

Commit fe656dc

Browse files
Merge pull request #367 from X-Sharp/master
Remove Sameword Highlights when the cursor moves to a whitespace area
2 parents f5d1789 + 9e2ed6a commit fe656dc

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/toolkit/Community.VisualStudio.Toolkit.Shared/MEF/SameWordHighlighterBase.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,20 @@ private void CaretPositionChanged(object sender, CaretPositionChangedEventArgs e
9898
UpdateAtCaretPosition(e.NewPosition);
9999
}
100100

101+
private void ClearSpans()
102+
{
103+
lock (_syncLock)
104+
{
105+
_currentWord = null;
106+
_wordSpans = new();
107+
SnapshotSpan span = new(_buffer.CurrentSnapshot, 0, _buffer.CurrentSnapshot.Length);
108+
TagsChanged?.Invoke(this, new SnapshotSpanEventArgs(span));
109+
}
110+
}
101111
private void UpdateAtCaretPosition(CaretPosition caretPosition)
102112
{
103113
SnapshotPoint? point = caretPosition.Point.GetPoint(_buffer, caretPosition.Affinity);
104-
114+
105115
if (!point.HasValue)
106116
{
107117
return;
@@ -117,6 +127,13 @@ private void UpdateAtCaretPosition(CaretPosition caretPosition)
117127
UpdateWordAdornments(word.Value);
118128
}, VsTaskRunContext.UIThreadIdlePriority).FireAndForget();
119129
}
130+
else
131+
{
132+
// Clear the spans, to make sure that the highlights are
133+
// removed when we move the caret to whitespace
134+
ClearSpans();
135+
}
136+
120137
}
121138

122139
private void UpdateWordAdornments(TextExtent word)

0 commit comments

Comments
 (0)