Hiding snippet highlights
Posted
Sat, Apr 15 2006 23:06
by
bill
sometimes having all the recent snippets you've added having all their replacement fields highlighted can lead to a lot of visual noise. Sometime ago
Cory Smith talked about this and wrote a macro to clear them all that involved closing the document and re-opening it. although Cory's approach worked it seemed a bit of overkill as it meant committing any changes to the documents, source safe issues etc.
Well earlier today, I was moving some code around and noticed that when I drag and dropped the code around the highlighting linking would disappear. This actually seems to be a bug in the way the VB editor does tracking. It does track through normal editor insertion keystrokes, but drag and drop, cut and paste seem to mess with that (understandably really <g>)
So rather than let a good bug go to waste I decided to exploit it :)
Sub Clear_Selected_SnippetHighlights()
Dim txtSel As TextSelection = TryCast(DTE.ActiveDocument.Selection, TextSelection)
If txtSel Is Nothing Then Return
DTE.UndoContext.Open("clear snippet highlights")
txtSel.Insert(txtSel.Text, vsInsertFlags.vsInsertFlagsContainNewText)
DTE.UndoContext.Close()
EndSub
With this macro, you simply select the text you want to clear the highlighting for and run the macro. El presto, the highlighting and tracking is gone. And you don't have to commit changes to disk or source safe. But wait.. there's still more….
notice the UndoContext in there ? That's right, you can Undo the change and the replacement fields will be highlighted and linked once again.
And the following macro clears all the snippet highlighting in the active document
Sub Clear_All_SnippetHighlights()
Dim txtSel As TextSelection = TryCast(DTE.ActiveDocument.Selection, TextSelection)
If txtSel Is Nothing Then Return
DTE.UndoContext.Open("clear snippet highlights")
Dim ep As EditPoint = txtSel.ActivePoint.CreateEditPoint
txtSel.SelectAll()
txtSel.Insert(txtSel.Text, vsInsertFlags.vsInsertFlagsContainNewText)
txtSel.MoveToLineAndOffset(ep.Line, ep.LineCharOffset)
DTE.UndoContext.Close()
End Sub
Enjoy :)