@JonB I was not aware of the built-in syntax highlighter and so built my own from scratch, basically following a train of thought from these two threads and using objc_util
: https://forum.omz-software.com/topic/2727/ui-textview-individual-words and https://forum.omz-software.com/topic/2014/beta-tinkering-with-pythonista-s-internals-using-objc_util/15. I checked the Pythonista site and a Google search for "OMTextView" and "OMSyntaxHighlighter" but can find nothing except passing references. Is this documented, or is this just something under the hood I'll have to investigate?
My custom syntax is indeed expressible as nested RegEx, which is essentially how I've implemented it myself (https://github.com/nbeversl/pythonista-crash-min-example/blob/master/syntax.py).
As a result of creating the "minimal example" for this thread, I discovered -- entirely by accident --that this crash is eliminated if the ObjCInstance
of the ui.TextView
is instantiated before any subviews are added to the main view (the parent of the ui.TextView
, which is a ui.View
). After that, calling add_subview()
through the (non-Objective-C) ui
module API on the main view works -- and the disabling/re-enabling of the scrolling described above also works.
I'm happy for the moment with any solution that gets my main project working, but at the same time I'm curious what I may not be understanding here -- is there something about an ObjCInstance
of a view that interacts poorly with non-ObjCinstance
sibling views, or is interfered with by changes to the parent view?