Send selected text from editor to board

Posted on
  • During testing I often missed a function to send selected code from Editor Window to the board.
    Examples are:

    • replace code for one function only
    • add a list of testing commands to source
    • recall functions like init
      Obviously use of copy from editor and paste in terminal would help.
      For my needs it became long-winded, and a hack was born.

    Installation of quick hack:

    • start webIDE ( in chrome browser
    • open devTools of chrome browser for this window
    • copy following source to devtools console
    • there should be a new button named P2B (post to board) at the end of editor buttons
    • select code, you want to sent
    • click the button

      a = document.createElement("a"); = "icon-paste";
      a.title = "paste to board";
      a.onclick = function(){
      var cm = Espruino.Core.EditorJavaScript.getCodeMi­rror();
      var txt = cm.getSelection();
      var tmp = Espruino.Config.RESET_BEFORE_SEND;
      Espruino.Core.MenuPortSelector.ensureCon­nected(function() {
      Espruino.Config.RESET_BEFORE_SEND = false;
        Espruino.Config.RESET_BEFORE_SEND = tmp;
      a.innerText = "P2B";
      x = document.getElementById("icon-deploy");
  • That's awesome. I find myself often enough doing the same thing.

    +1 for making this a standard feature of the WebIDE :)

  • Nice, thanks! This seems like a really neat idea.

    Having a key shortcut would be even more useful - I just added some code to make key shortcuts nice and easy, so I might try adding this there.

  • I love feedback like this :-))
    @Gordon, may be, you could add something like addShortcut to Espruino.Plugins.KeyShortcuts ?

  • That's good feedback too ;) Actually SHORTCUTS was public you could just do Espruino.Plugins.KeyShortcuts.SHORTCUTS[­"Ctrl + X"] = ...

    I'll add that now.

    This is probably overkill but potentially if nothing was selected and the cursor was in a global function, the IDE could automatically upload that whole function... With the Acorn parser (used in the 'compiled'/etc handling) it's probably not such a big deal to do.

  • Ok, just pushed it - but it's not live on yet. Currently I'm using Ctrl + \ but I'm open to more sensible key combinations

  • if nothing was selected and the cursor was in a global function, the IDE could automatically upload that whole function

    would definitively speed things up

    Currently I'm using Ctrl + \ but I'm open to more sensible key combinations

    On german keyboard layout the \ needs to be used with Alt Gr, so Ctrl+Alt Gr+\
    Maybe not a big deal, but could be bothersome.

  • The availability of a partial update can open can of worms... because its proper working depends on various things that require understanding of how Espruino works. So the documentation should include some warning / caution that this is an advanced function and its use could render the application broken... (You need to know what you are doing).

  • Tue 2020.02.25

    I know I'm going to take a ton of flak for making this observation, but in the fun of those of us that know the poster experience level here. . . .

    'You need to know what you are doing'

    Editing in two browser instances at the same time are we?

  • Shift-enter works as a shortcut in some REPLs, I would prefer that.
    Like @Raik, on a hungarian keyboard, you can't just press Ctrl + \ easily.
    Oh, while we are at keyboard shortcuts: [] characters are on AltGr-F and AltGr-G on a hungarian keyboard, but that conflicts with Web-Ide's show/hide "right side". So making that configurable would be nice :)

  • Ok, shift-enter sounds good. I'll make the change.

    re: 'Web-Ide's show/hide "right side"' - not quite sure what you mean? Alt/Alt-Gf + F doesn't seem to do anything for me. Ctrl-F goes fullscreen which might be what you mean? I'm not sure how that can get confused with AltGr though?

  • Oh, looks like it's a Native Ide only thing.
    If I connect to a device, go to the left side (terminal) and hit AltGr-F, it does the same as if I hit CTRL-F. But only the Native Ide, assumed it does the same everywhere. I'm on win 10...

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Send selected text from editor to board

Posted by Avatar for JumJum @JumJum