locked
How do I set the IVsTextView default font? RRS feed

  • Question

  • I am writing a Visual Studio 2010 extension that uses the IVsTextView to edit a custom content type. I'm using MEF extensions (I wish to avoid writing an implementation for ILanguageService).

    I defined 3 classifiers and appropriate ClassificationFormatDefintions, which provide the color and font for the tags.

    However, the text also contains 'unclassified' content. I was not able to change its color nor its font.

    • I tried changing the 'Plain Text' item in the "Text Editor" category, but it did not have any effect.
    • I tried applying properties on the IEditorFormatMap interface, but the properties I tried did not have an effect. I'm not even sure they were correct properties.

    I also thought about (though did not try) adding an 'unclassified' classifier and provide the appropriate tagger info for it. But this seems like the wrong way to do it.

    So, how do I set the font for the unclassified content?

    Alternatively, how do I relate the IVsTextView to the items in "Text Editor" font and colors category?

    Thursday, September 11, 2014 6:33 AM

Answers

  • After some further digging I realized that the easiest solution is to:

    1. Provide a default Classification Type Definition which sets the font as I please.
    2. Add an overall tag span (ranging from the beginning of the text to its end), whose classification type is the default classification.

    This is later reordered by the Classification Aggregator, which causes classification tags with smaller spans to take precedence over the default tag span, so colors are applied correctly as well.

    • Marked as answer by rmashal Monday, September 22, 2014 1:13 PM
    Monday, September 22, 2014 1:13 PM

All replies

  • Hi rmashal,

    Can you please post your code here, or just upload your sample project in OneDrive so that I can reproduce this problem easily?

    The following links should give you some help:

    How to: Access the Built-in Fonts and Color Scheme

    Extending the 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.

    Sunday, September 14, 2014 2:40 AM
  • After some further digging I realized that the easiest solution is to:

    1. Provide a default Classification Type Definition which sets the font as I please.
    2. Add an overall tag span (ranging from the beginning of the text to its end), whose classification type is the default classification.

    This is later reordered by the Classification Aggregator, which causes classification tags with smaller spans to take precedence over the default tag span, so colors are applied correctly as well.

    • Marked as answer by rmashal Monday, September 22, 2014 1:13 PM
    Monday, September 22, 2014 1:13 PM