Adding lines to Document using AppendText

SyntaxEditor for Windows Forms Forum

Posted 16 years ago by Matt Adamson
Avatar
Guys

I'm trying to add lines to a Document instance using AppendText however it seems a document instance always has one line which is causing strange errors in my code which works a line at a time e.g. for commparios with another document ( basic file comparison )

Is there any way to ensure 1 DocumentLine object exists in the collection when one line is added?

Cheers

Matt

[Modified at 06/04/2008 03:58 PM]

Comments (8)

Posted 16 years ago by Matt Adamson
Avatar
Guys

Perhaps this is related to the issue however I've also noticed an odd issue with the custom line no value for a DocumentLine instance.

I currently have code such as
rightDocument.AppendText(differences.Right[positionIndex].ToString() + Environment.NewLine);

DocumentLine rightFileLastLine = rightDocument.Lines[rightDocument.Lines.Count - 2];
rightFileLastLine.CustomLineNumber = rightCurrentLineNo.ToString();
The ( - 2 ) value because of the previous issue I mentioned regarding a null DocumentLine instance always being present in the Document at the end. However I've found that sometimes although the custom line no appears to add in sequence e.g. 28, 29, 30. When the editor shows the document it sometimes shows 29, 30 and then jumps to 33 for the last line.

However what's also odd is when I debug and view the Document instance e.g.

rightDocument.Lines[29].CustomLineNumber = "29"
rightDocument.Lines[30].CustomLineNumber = "30"
rightDocument.Lines[31].CustomLineNumber = null
rightDocument.Lines[32] - Throws argument exception in watch window

Even though the values in the debugger look as expected it shows a 33 after the 30, very confusing, where is it getting the 33 from.
Posted 16 years ago by Matt Adamson
Avatar
Perhaps the syntax editor control itself is coming up with the 33 value and putting it because the CustomLineNo for the last line is null. Although it's an odd no to come up with, at least I would have expected 31 if anything.

Is there anyway to get rid of this annoying line which keeps hanging about at the end :)

[Modified at 06/04/2008 03:58 PM]
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Matt,

There always will be at least one DocumentLine in the Document. Depending on how many line feeds are in the text you add, then you add more lines.

When the custom line number is null (not set) it will show the display line index + 1 as the displayed number. I'm not sure how you are seeing a 33 unless it's for display line index 32.

A side note, you can set the custom line number to "" (empty string) to blank it out.


Actipro Software Support

Posted 16 years ago by Matt Adamson
Avatar
Thanks that would explain why then because some of the lines don't have any custom line no e.g. for lines which are removed on the right file.

Is there no easy way to just get rid of this line though because it's just pointless and has no data but yet exists in the editor.
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
If you don't add the newline at the end of your text, then it won't be there. That is what is adding the extra line.


Actipro Software Support

Posted 16 years ago by Matt Adamson
Avatar
But I don't add this line e.g. if you start with a blank document it has one line.

You then call

AppendText("Some code" + Environment.NewLine);

Lines is now count of 2.
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
That is correct. As I mentioned, there always is at least one line, even if the document is empty. If you don't want a second line after your first append, then don't put in Environment.Newline. That is creating a second line. If you don't want the initial line when the document is empty to show a line number then set its CustomLineNumber to "".


Actipro Software Support

Posted 16 years ago by Matt Adamson
Avatar
The trouble is my code iterates through all text lines and appends the text with Environment.NewLine each time as it's difficult to check at the point AppendText is called whether this line is the last line.

Although if this is the only way to do it and it's not possible to remove that last line easily at the end I'll have to find a way.
The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.