Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Text Styling in ui.TextView
-
Is there a way I can change individual text inside a TextView object? I want to make my own code/text editor. I want to implement syntax highlighting.
If there is any way you could show me an example of how, that would be great.
Thanks,
Sean -
-
https://forum.omz-software.com/topic/2727/ui-textview-individual-words
Another option would be to use javascript/html for display with a backend in python. Here was an example I made a few years ago, which used the CodeMirror editor, which includes syntax highlighting fir a few dozen languages, with some backend work like opening and saving files done via the webview delegate methods in python.
Another option, which frankly I have not explored at all, would be to extend the objc OMTKSyntaxHighlighter. But this could be a little difficult to reverse engineer without creating some custom logging classes that record the inputs and output classes.
-
Thanks so much for your help. I decided to start my own version of a Microsoft Word instead of just a Markdown editor. I have the font sizes working so far, and I am loving it.
The only problem I don't know how to fix currently: reading through the text field, while also scanning all of the individual character and font attributes. That way I can save the rich text to files, and then the states of the characters can be reloaded again.
-
If you read the docs for nsattributedstring, there are some methods to extract the underlying RTF data, which you can save in a file. Or, load a RTF file into a textfield...
Here is a simple proof of concept.
https://gist.github.com/b2436247405bb2ee81c1a52f5f2f3e83 -
actually, looks like you can actually read or write quite a few file formats, including word doc files directly... requires slightly different calls
-
@JonB sounds great. Thanks for the info. I'll get back to you on my progress; if I have any questions.