I've got a project that involves highlighting a custom syntax I've created. The highlighting happens on textview_did_change() in the delegate of a ui.TextView() that is a subview of the main view, which is a ui.View().
When editing more than one screenful of text, the rewrite of the NSMutableAttributedString to the TextView moves the cursor to the end of the file briefly and, depending on view position, can cause the view to scroll away from the editing point. To mitigate this, I've attempted to disable scrolling before the call to the syntax highlighter, and re-enable it afterwards. I also save the cursor position and restore it. I'm not sure I've gone about all of this in the cleanest possible way, but it works.
The problem is that it crashes if a second subview is added to the main view using add_subview(). I discovered this is the trigger only by commenting out code until I isolated it. I get no ObjectiveC exception log in the folder to give me a clue to what is going wrong.
I've posted a minimal example at https://github.com/nbeversl/pythonista-crash-min-example. syntax.py is the code for the highlighting that I'm using in the project. main.py is a minimal example that reproduces the problem.
The example works as is. To see the crash, uncomment line 84 and then try typing text into the textview.
Adding subviews works fine (no crashes) if the scrolling behavior is not changed before and after the update.
Is there another way to prevent the scrolling/cursor positioning issues when calling the highlighting, or if not, what is the interaction between that and the secondary subview that causes the crash and how to fix?
The main project has about 8 subviews ; adding any one of them causes this crash.