Posted 14 years ago
by Mick George
-
Principle Software Engineer,
CNC Software, LLC
Version: 11.1.0540

I have a custom margin that is used to set breakpoints, the user left clicks on the margin and a break point is added or removed as needed.
Each break point stores a TextSnapshotRange.StartOffset TextSnapshotRange.EndOffset TextSnapshotRange.StartPosition Text and line Number. OnDocumentTextChanged is implemented in my Custom Margin class to keep each break point properties in sync with the latest snapshot. The user can add/remove break points add or remove lines in the view and break points update and display as expected.
I also created a BreakPointTagger to draw a rectangle around a line of text that a break point has been added to. I have code that determines whether an adornment can be drawn shown below. The code below is working correctly in all cases except when the cursor is at the start of a line when the user presses the enter key.
BreakPointTagger.csBreak points enabled.
Lines added above existing break points:
Line added with cursor on a break point at the line start notice that the adornments are not drawn because the code check above fails.
I assume I am doing something and would appreciate any help you can give, thank you.
Each break point stores a TextSnapshotRange.StartOffset TextSnapshotRange.EndOffset TextSnapshotRange.StartPosition Text and line Number. OnDocumentTextChanged is implemented in my Custom Margin class to keep each break point properties in sync with the latest snapshot. The user can add/remove break points add or remove lines in the view and break points update and display as expected.
I also created a BreakPointTagger to draw a rectangle around a line of text that a break point has been added to. I have code that determines whether an adornment can be drawn shown below. The code below is working correctly in all cases except when the cursor is at the start of a line when the user presses the enter key.
BreakPointTagger.cs
// Loop through the snapshot ranges
foreach (TextSnapshotRange snapshotRange in snapshotRanges)
{
// If the snapshot range is not zero-length...
if (!snapshotRange.IsZeroLength)
{
// Get a snapshot reader
ITextSnapshotReader reader = snapshotRange.Snapshot.GetReader(snapshotRange.StartOffset);
// If not already at the start of a line, back up to the start
if (!reader.IsAtSnapshotLineStart)
{
reader.GoToCurrentSnapshotLineStart();
}
// Read through the snapshot until the end of the target range is reached
while ((!reader.IsAtSnapshotEnd) && (reader.Offset < snapshotRange.EndOffset))
{
// Save the start of the line offset
int lineStartOffset = reader.Offset;
// Go to the end of the line
reader.GoToCurrentSnapshotLineEnd();
// Save the end of the line offset
int lineEndOffset = reader.Offset;
// Query our breakpoint list to see if we have a breakpoint at this position
DebuggerBreakPoint bp = this.debugpoints.FirstOrDefault(s => s.StartOffset == lineStartOffset && s.EndOffset == lineEndOffset);
if (null != bp)
{
// Create a new tag from the breakpoint
BreakPointTag tag = new BreakPointTag(bp);
// Yield the tag
yield return new TagSnapshotRange<BreakPointTag>(
TextSnapshotRange.FromSpan(snapshotRange.Snapshot, snapshotRange.StartOffset, snapshotRange.Text.Length), tag);
}
// Consume the newline
reader.GoToNextSnapshotLineStart();
}
}
}
Lines added above existing break points:
Line added with cursor on a break point at the line start notice that the adornments are not drawn because the code check above fails.
I assume I am doing something and would appreciate any help you can give, thank you.