icsharpcode / AvalonEdit

The WPF-based text editor component used in SharpDevelop
http://avalonedit.net/
MIT License
1.87k stars 470 forks source link

Exceptions working with collapsed sections and using RectangleSelection #202

Open FrankyB5 opened 5 years ago

FrankyB5 commented 5 years ago

Hi! When using a RectangleSelection, using the Alt keyboard and mouse, while having collapsed sections, causes exception. I've put both exceptions in this issue, since they seem to be related.

First exception is: an InvalidOperationException with the message "Line 42 was skipped by a VisualLineElementGenerator, but it is not collapsed.",

Repro:

Welcome to AvalonEdit! if { }

if { }

image

Second related exception ArgumentOutOfRangeException with: "0 <= offset <= 1550 Parameter name: offset Actual value was 1987."

Repro:

image

I haven't found any quick fixes or workarounds for this.

Let me know if you have any clues or any tips to have that fixed. Thanks François

mzbik commented 4 years ago

You can make this simpler by deleting a box that contains a collapsed region at the end of the file with no EOL or deleting a collapsed region that includes more than the EOL. Basically, you get called to generate a line at EOF (offset == document length) and the code asserts since you're at EOF.

N.B., there's an issue in that the Folding data for the lines isn't updated when the Selection is updated (which then uses the Folding generator to produce lines). This ordering dependency should be handled explicitly in TextArea::OnDocumentChanged rather than relying on notification ordering.