Fix/text changed event args changed range #215
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.