iOS Text Entry
In iOS, there are two provided text input controls. UITextField provides a simple text field. It's great for entering things like usernames and search queries. UITextView is for longer form text, like a document body. Both of these controls support a global style for the text they display.
Because Genesis is a source code editor, I need to have a text input control that supports multiple styles. This can be done in one of two ways:
I initially tried the first approach. I explored having a hidden, invisible
div that would take editing focus, and have the syntax highlighting view at exactly the same location. Matching up scrolling seemed pretty hacky. I next tried using
contenteditable on the
div containing the highlighted code. When I started looking into key events to trigger re-highlighting the text, it became apparent that this was not an elegant solution.
I decided to pursue the second route. Native is better, and I can provide a more customized experience with regards to the caret and text selection. This also gives me an excellent opportunity to learn Core Text.
I have an early iteration of this custom text editing view, which I'm calling
GNTextView, in the customTextView branch of the Genesis Github repository. It supports text input, most cursor movement operations, and displays
NSAttributedString. It's early, but solid progress towards a great source code editing experience.