locked
Custom code formatting extension

    Question

  • Hi Folk,

    I want to create extension that change tab offsets in custom manners,  while overriding tab offsets in ITextParagraphPropertiesFactoryService I noticed that sometimes it takes 1 or more seconds to indent other lines

    Here is the code I have created, don't pay attention to the logic, I just put rand for the sample, running this code you can feel a delay between two line formattion

    [Export(typeof(ITextParagraphPropertiesFactoryService))]
    	[ContentType("code")]
    	public class MyParagraphPropertiesFactoryService : ITextParagraphPropertiesFactoryService
    	{
    		ITextVersion oldVersion;
    		double offSet;
    
    		public TextParagraphProperties Create(IFormattedLineSource formattedLineSource, TextFormattingRunProperties textProperties,
    		IMappingSpan line, IMappingPoint lineStart, int lineSegment)
    		{
    			var curV = formattedLineSource.SourceTextSnapshot.Version;
    			if (oldVersion != curV)
    			{
    				Random rand = new Random();
    				offSet = formattedLineSource.ColumnWidth * 10 + rand.Next() % 50;
    				oldVersion = curV;
    			}
    			return new MyParagraphProperties(textProperties, formattedLineSource, 10, offSet);
    		}
    	}
    	public class MyParagraphProperties : TextFormattingParagraphProperties
    	{
    		List<TextTabProperties> _tabs;
    		double offset;
    		public MyParagraphProperties(TextFormattingRunProperties textProperties, IFormattedLineSource formattedLineSource, int firstTabSize, double offSet)
    			:
    		   base(textProperties, formattedLineSource.ColumnWidth * (double)formattedLineSource.TabSize)
    		{
    			ColumnWidth = formattedLineSource.ColumnWidth;
    			FirstTabSize = firstTabSize;
    			offset = offSet;
    		}
    		public override IList<TextTabProperties> Tabs
    		{
    			get
    			{
    				return new List<TextTabProperties> { new TextTabProperties(TextTabAlignment.Left, offset, 0, 0) }; ;
    			}
    		}
    
    		public double ColumnWidth { get; set; }
    		public int FirstTabSize { get; set; }
    	}

    So the question is, is this correct way to write custom tab formatter? if yes, why visual studio deals so slow with it? are there any ways to give different tab indent for different tabs in the same line?

    Thanks,
    Arsen


    • Edited by Arsen Mkrtchyan Sunday, June 03, 2012 9:35 PM
    • Moved by Ryan MoldenMicrosoft employee Sunday, June 24, 2012 6:27 PM This is an editor specific extensibility question, moving to editor forum for higher likelihood of someone with expertise seeing it. (From:Visual Studio Extensibility)
    Sunday, June 03, 2012 9:35 PM

All replies

  • Hi Arsen,

    I think you can write your custom tab formatter as you did. But I don't know why it dealt so slow.

    This reference may be helpful to you:http://www.go4answers.com/Example/programatically-invalidate-certain-4975.aspx

    Best regards,

    Disley

    Monday, June 04, 2012 8:03 AM
  • Hi Disley,

    Thanks for response, I will take a look to the url you drop in message ang get you back with result

    Arsen

    Monday, June 04, 2012 7:16 PM
  • Hi Disley,

    It doesn't seems to work, again it takes few seconds to refresh formatting, I can send you sources to review if you drop mail here, or write me mkrtchyan.arsen at gmail com. what do you think about making fake edit? could it refresh formatting?

    Arsen 

    Saturday, June 16, 2012 1:45 PM
  • I have created sample here which shows that ITextParagraphFactoryService formats text slow, could you please find few mintues to review?

    Thanks,

    Arsen

    Saturday, June 23, 2012 7:21 PM