locked
HIghlight particular line number provided in textbox which is in a tool window RRS feed

  • Question

  • Hi , I am looking for how i can highlight a particular line number which is provided by the user in vs package . I am aware that this can be done through MEF but i did not get any solution so far .

    Suppose in code editor window my opened document has following line at line number 53 .

    53     this.close();

    user will provide a line number which he wants to highlight in a textbox which is in tool window . if he provides 53 then the above piece of code gets highlighted because that is line number 53 .


    Friday, May 22, 2015 7:26 PM

Answers

All replies

  • Hi , I am looking for how i can highlight a particular line number which is provided by the user in vs package . I am aware that this can be done through MEF but i did not get any solution so far .

    Hello,

    Try to firstly move to the specified line by the input line number, check the code in this thread:

    How to highlight one line (isolated mode)

    After you get the caret moved to the specified line, use the IWpfTextView object to get the current line's ITextViewLine object,

    IWpfTextView.GetTextViewLineContainingBufferPosition Method

    IAdornmentLayer interface will help you to highlight the line.

    IAdornmentLayer Interface

    This is a sample MEF project provides the details of the implementation:

    A sample VS2010 extension that hilights the current line in the text editor


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Gchawla Tuesday, May 26, 2015 1:09 PM
    Monday, May 25, 2015 8:18 AM
  • Thanks for your reply . it really helped me .

    One more thing , I have new requirement of showing a glyph on indicator margin at the given line number . I had gone through following  sample  

    https://msdn.microsoft.com/en-us/library/vstudio/ee361745(v=vs.110).aspx

    but problem here is GetTags method of ToDoTagger class is automatically called on load or whenever we edit something in code . 

    I am not able to understand how i can call it explicitly from the tool window code like i asked in my first question . user will provide a line number and i want the glyph should be drawn on that line number .

    I don't want this GetTags method to be called implicitly at any point of time (on load and editing) . I just want this to be called whenever required or any other way i can have the glyph drawn on particular line number .

    Thanks in advance .


    Tuesday, May 26, 2015 1:09 PM
  • I haven't implemented this functionality ever, but I think you could try to use some global string variable to store the content of the line where the caret locates. IWpfTextView.Caret.PositionChanged event will help to to find the current line, refer to this code sample for how to use this event:

    A sample VS2010 extension that hilights the current line in the text editor

    Then find the string value in the GetTags method, if found, return the TagSpan.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, May 27, 2015 8:53 AM