omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    3
    7
    5477
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • AtomBombed
      AtomBombed last edited by

      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

      1 Reply Last reply Reply Quote 0
      • Webmaster4o
        Webmaster4o last edited by

        For syntax highlighting specifically, try this example by @omz. @JonB posted a more flexible approach a while back, but I can't find it

        1 Reply Last reply Reply Quote 0
        • JonB
          JonB last edited by

          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.

          1 Reply Last reply Reply Quote 1
          • AtomBombed
            AtomBombed last edited by

            @Webmaster4o @JonB

            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.

            1 Reply Last reply Reply Quote 0
            • JonB
              JonB last edited by

              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

              1 Reply Last reply Reply Quote 0
              • JonB
                JonB last edited by JonB

                actually, looks like you can actually read or write quite a few file formats, including word doc files directly... requires slightly different calls

                1 Reply Last reply Reply Quote 0
                • AtomBombed
                  AtomBombed last edited by

                  @JonB sounds great. Thanks for the info. I'll get back to you on my progress; if I have any questions.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Powered by NodeBB Forums | Contributors