Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo crashes when editing text #39

Closed
Wouter01 opened this issue Jan 30, 2024 · 9 comments
Closed

Demo crashes when editing text #39

Wouter01 opened this issue Jan 30, 2024 · 9 comments

Comments

@Wouter01
Copy link
Contributor

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)

@mattmassicotte
Copy link
Contributor

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

@mattmassicotte
Copy link
Contributor

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

@mattmassicotte
Copy link
Contributor

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
Copy link
Contributor

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

@Wouter01
Copy link
Contributor Author

Wouter01 commented Feb 1, 2024

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)

@mattmassicotte
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

invalidation problem: #40

@Wouter01
Copy link
Contributor Author

Wouter01 commented Feb 2, 2024

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

@Wouter01 Wouter01 closed this as completed Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants