In Visual Studio 2008 I would regularly record a macro to (for example) take a list of class member declaratio开发者_如何学JAVAns and turn it into a list of property definitions.
Using Visual Studio 2010, the macro recorder appears to ignore a 2nd press of the Home key (the 1st should take you to the start of the text on the line, the 2nd should take you to the character position 1 on the line).
Putting the cursor at the end of a tabbed line, starting to record and pressing "Home" twice results in the following (it doesn't matter whether the tabs are actual tabs or spaces)...
Sub TemporaryMacro()
DTE.ActiveDocument.Selection.StartOfLine(VsStartOfLineOptions.VsStartOfLineOptionsFirstText)
End Sub
When what it should really put is...
Sub TemporaryMacro()
DTE.ActiveDocument.Selection.StartOfLine(VsStartOfLineOptions.VsStartOfLineOptionsFirstText)
DTE.ActiveDocument.Selection.StartOfLine(VsStartOfLineOptions.VsStartOfLineOptionsFirstColumn)
End Sub
I know I could just go in and edit it, but as I normally record something and then immediately run it multiple times, that is not appealing. And I'm not aware of any keypress that will take you to the first column.
Can anybody confirm if this is a fault with the macro recorder in VS2010, or am I doing something really stupid?
This does not work for me, either, meaning it does the same thing for me as it does for you, and the macro does not play back correctly.
As a workaround, I use the key combo [end, right, up] to go to the first character position when recording a macro. This translates into:
DTE.ActiveDocument.Selection.EndOfLine()
DTE.ActiveDocument.Selection.CharRight()
DTE.ActiveDocument.Selection.LineUp()
The only time this doesn't work is when you operate on the last line of the file. If you anticipate that happening you could use [up, end, right] instead:
DTE.ActiveDocument.Selection.LineUp()
DTE.ActiveDocument.Selection.EndOfLine()
DTE.ActiveDocument.Selection.CharRight()
Of course, this version would not operate correctly on the first line of the file.
精彩评论