ChimeHQ / Neon

A Swift library for efficient, flexible content-based text styling
BSD 3-Clause "New" or "Revised" License
319 stars 17 forks source link

Demo crashes when editing text #39

Closed Wouter01 closed 7 months ago

Wouter01 commented 7 months ago

The demo project provided in the repo will crash when trying to edit the text. Some checks seem to fail, and it looks like it depends where in the text something is edited.

Here are the cases that I found:

mattmassicotte commented 7 months ago

Ok, first crash is caused by a bogus RangeMutation limit calculation. Looking into a test for it now.

mattmassicotte commented 7 months ago

Ok, test to expose the bug and confirm fix done. Kind of a dumb mistake.

mattmassicotte commented 7 months ago

That one was a bit of a special-case though. Any edit at a location < the ending will also almost certainly fail. This is because the RangeMutation being constructed doesn't use the processed length, resulting in parsing that is too limited in how much content it can see.

mattmassicotte commented 7 months ago

Ok, I think that one is resolved too. I bet these aren't the last, but I really appreciate you reporting them!

Wouter01 commented 7 months ago

Thanks a lot! I can confirm that both cases seem to be solved now. There seem to be some more cases where the first assertion will fail (assertionFailure (RangeMutation.swift -> transform(location:), line 84)). Some that I noticed:

When trying to remove the last character, another assertion will fail: assert(range.max <= l, "range must not exceed limit") (RangeMutation.swift -> init(range:delta:limit:), line 24)

mattmassicotte commented 7 months ago

Ok one of these was easy. Tests expanded, bug exposed and fixed. But there's still at least one range management bug lurking.

Just so you know, the reason this stuff is so strict is because the entire system works on deltas. If even one is wrong, all future calculations won't ever work right again.

mattmassicotte commented 7 months ago

OK more progress. I fixed another serious limit calculation, and also removed a check that was left-over from some now-removed code. Things are better. But, the example isn't re-highlighting correctly on changes. Any more crashes?

mattmassicotte commented 7 months ago

invalidation problem: https://github.com/ChimeHQ/Neon/issues/40

Wouter01 commented 7 months ago

Yup, can't find any crashes anymore! Thank you!