AvaloniaUI / AvaloniaEdit

Avalonia-based text editor (port of AvalonEdit)
MIT License
746 stars 148 forks source link

System.NullReferenceException on Undo #425

Closed workgroupengineering closed 2 months ago

workgroupengineering commented 4 months ago

How to simulate:

Rekkonnect commented 4 months ago

The action of adding a snippet adds multiple lines and thus exposes the lack of checking whether the invalidated line range is out of bounds. The call stack shows that the exception is ultimately thrown by TextMateSharp because it attempts to read the line at the given index, without checking whether it's in bounds. This can be retrieved via the GetNumberOfLines() method from the model, and evaluated such that InvalidateLineRange(int, int) doesn't run the loop with out of bounds indexes.

@danipen Does this belong to https://github.com/danipen/TextMateSharp? Then this issue would track the respective issue in that repo.

danipen commented 4 months ago

I'd say this should be fixed at this layer: https://github.com/AvaloniaUI/AvaloniaEdit/blob/master/src/AvaloniaEdit.TextMate/TextEditorModel.cs