Open codingdave opened 3 years ago
Hi @PavelTorgashov what do you think about this PR? Do you have any interest in this patch? If so, what is missing for you to accept this PR?
Kind regards
Hi @PavelTorgashov any updates on this? Is this project dead?
Short: I have observed that the Range Start setter also changes the end field. That leads to
Long
Range.Start
modifiesRange.End
. Start and End are equal. That may lead to unexpected behavior.updatingRange.Start
is overwritten and such the bottom end of the accumulated rangeupdatingRange.End
gets lost. This also leads toupdatingRange.GetIntersectionWith(Range)
being a noop but much more important: The ChangedRange will always only be line that was changed at last.I have fixed that issue in this PR. Because it is hard to see where this behavior (Start == End) is required I have added a function
SetStartAndEnd
that is explicitly doing what it says: Setting Start and End at the same time. Then I went through all the code and have inserted that function whereever Range.Start was assigned and not Range.End was assigned in the next line:TB.Selection.Start = new Place(0, LineIndex)
Also have left lines untouched that are assigning End to Start:
Start = End;
In the second step I have changed the Range.Start setter to not any longer modify Range.End.
I have also created a sample application that demonstrates that behavior, but it is not part of this PR. You can find it here: https://github.com/codingdave/FastColoredTextBox/tree/fix/TextChangedEventArgs-ChangedRange-Sample
These are the screenshots of the sample. Green is unchanged text, Red is the
ChangedRange
and black is the new text that is added and not part of theChangedRange
, so you can say that is the error that this PR fixes.Before the fix
After the fix
One further note: I have left the VB code untouched, as this is not my comfortable language.