0

I've written an extension to comb through code files line by line to detect certain patterns. The problem I'm seeing is that lines within collapsed sections are skipped when using TextSelection.LineDown() or similar. I'm aware that TextSelection.OutlineSection() exists to create such sections, but is there a way to detect, and possibly expand or collapse them?

Jake
  • 733
  • 8
  • 23
  • It sounds like you are more interested in the text of a document than you are in the outlining regions of the document. If this is a correct statement, then you probably don't want to manipulate the outlining regions at all (it would be distracting to users) and should instead ask a question regarding the underlying true problem you are trying to solve. – Sam Harwell Dec 17 '14 at 17:28
  • @SamHarwell You're correct that I don't care much about the outlining regions, but the problem I'm having is that `TextSelection` does, badly. The underlying problem is how to cleanly read a text document line by line if `TextSelection.LineDown()` can move from the `TextSelection` line 4 to 13 if it encounters a collapsed outlined selection on lines 5-13. – Jake Dec 18 '14 at 20:39
  • `TextSelection` is not what you want to use. You should ask a new question regarding getting the text of a document. It would be very helpful if you can point us to your code, or give details about the version(s) of Visual Studio you want to support and how you plan to distribute the resulting extension. – Sam Harwell Dec 18 '14 at 22:39

1 Answers1

1

In your scenario you don't have to use TextSelection, since that is related to...text selection. To traverse the lines of a code file, given an EnvDTE.TextDocument, you have the TextDocument.StartPoint property to get a EnvDTE.TextPoint and then you create an EnvDTE.EditPoint with TextPoint.CreateEditPoint(). With an EnvDTE.EditPoint you can GetText(...), MoveToXXX(...) etc. EditPoints are not affected by collapsed text.

Carlos Quintero
  • 4,300
  • 1
  • 11
  • 18
  • This did the trick, thanks for pointing out EditPoint as it was exactly what I needed. – Jake May 12 '15 at 20:23