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.


    How to retrieve selected text in ui.WebView?

    Pythonista
    2
    3
    2074
    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.
    • zipit
      zipit last edited by

      Hi, is it possible to get the currently selected text inside a ui.WebView? I am aware that I could copy the text manually to the clipboard and then retrieve its content with Python but I would like to avoid that additional step. I was hoping for some ObjC magic, so that I could invoke the WebViews Edit menue copy function programmatically.

      Cheers
      zipit

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

        No need for objc_util, you can use JavaScript:

        selected_text = web_view.eval_js('document.getSelection().toString()')
        
        1 Reply Last reply Reply Quote 0
        • zipit
          zipit last edited by

          Oh, thanks, that was quick!

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