sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    How to properly handle escape characters?

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 3 Posters 312 Views 3 Watching
    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.
    • A Offline
      Anton_S
      last edited by

      Can anyone help me on handling escape characters?
      Currently I got this code:

      
      editor.on("change", function(e){
        var code = editor.getSession().getValue();
        window.location.href = 'skp;editor_changed@' + code;
      });
      

      What it does is sends editor's script to a ruby callback, but the escape characters are converted to nothing or sometimes raise an error. I need a way to properly handle escape characters, so that I can get the same script after passing code to ruby.

      I'm pretty sure Aerilius done something similar with his Ruby Console +, but I don't have enough brains to understand it.

      1 Reply Last reply Reply Quote 0
      • A Offline
        Aerilius
        last edited by

        Such webdialog issues have been discussed in many places elsewhere (like here), I think it's not too far fetched to say the skp: protocol is unreliable and for many use cases "dead". It does not only need url-encoding ( %) + string escaping ( \), but it also looses certain combinations of characters. When it returns the string url-decoded to ruby it causes ruby to have issues with some decoded characters.

        I suggest to use skp: only for a small set of known identifiers of limited character range (names of your callbacks).
        If you need to transfer user data (that could potentially contain any character like quotes or Chinese), let the Ruby API fetch the string from a hidden input field using get_element_value.

        Me and thomthom do this for all communication between Ruby and Webdialogs using a message pipe (see thomthom at github, or mine). Please don't waste too much valuable time with webdialog issues, but try to re-use what we have already worked out.

        The purpose of an API interface is to hide its implementation details. It would be good if SketchUp incorporated a repaired or new communication model as default, so that developers can make plugins "on top" of the API instead of working around issues below the API.

        1 Reply Last reply Reply Quote 0
        • A Offline
          Anton_S
          last edited by

          @aerilius said:

          let the Ruby API fetch the string from a hidden input field using get_element_value

          From my understanding, I should first assign editor.session().getValue() to the hidden input text and then use dlg.get_element_value("hidden_input_text")?


          Edit:
          Actually a hidden input does not allow multi lines. I used textarea with display:none; style instead. From my current observations the technique works amazing!

          1 Reply Last reply Reply Quote 0
          • tt_suT Offline
            tt_su
            last edited by

            @anton_s said:

            Actually a hidden input does not allow multi lines. I used textarea with display:none; style instead. From my current observations the technique works amazing!

            Oh! ... ooh... I might have to revisit SKUI and check this.

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement