Fix/text changed event args changed range#215
Fix/text changed event args changed range#215codingdave wants to merge 3 commits intoPavelTorgashov:masterfrom
Conversation
|
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? |
|
@codingdave Unfortunately, there has been no activity at all from @PavelTorgashov for at least 4 years now, I fear he may have been affected by the conflict in the Ukraine. I have created a Fork in which I have been applying some of the fixes proposed on the main project. Could you open this same PR for my fork of this project? I believe your code change could resolve an issue that I have been seeing with C# syntax highlighting in certain files. |
3dec48c to
3531169
Compare
3531169 to
b4699c1
Compare
|
@codingdave Hello again, and great news! Pavel has allowed me to assist in maintaining this project, I would like to do some testing around your change. But I am curious as to the exact bug that is fixed by this change. It looks to me like there is a possibility that the FCTB syntax highlighting behavior is what is affected by this change (going by the screenshots) or is this just related to the range of changed text being sometimes incorrect? |
Short:
I have observed that the Range Start setter also changes the end field. That leads to
Long
Range.StartmodifiesRange.End. Start and End are equal. That may lead to unexpected behavior.updatingRange.Startis overwritten and such the bottom end of the accumulated rangeupdatingRange.Endgets 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
SetStartAndEndthat 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
ChangedRangeand 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.