ChimeHQ/Neon

Demo crashes when editing text

Wouter01 opened this issue · 9 comments

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:

  • Put cursor at end of last line, press enter:
    assertionFailure (RangeMutation.swift -> transform(location:), line 84)

  • Put cursor after let, type a:
    assertionFailure("location is greater than end") (String+Data.swift -> data(at:limit:using:chunkSize:), line 19)

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

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

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.

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

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 a character gets removed
  • When adding a " character
  • When adding a \ behind "hello world"

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)

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.

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?

invalidation problem: #40

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