sdether / josh.js

Toolkit for building a bash-like shell in the browser, including full readline support
http://sdether.github.com/josh.js/
Apache License 2.0
390 stars 76 forks source link

copy/paste #28

Closed coderofsalvation closed 9 years ago

coderofsalvation commented 9 years ago

scenario: in another browsertab I have an url..I select the url, rightclick copy. I try to paste it into josh.js but it doesnt work on chrome 41.0

any ideas?

I tried:

  $("span.cursor").bind('paste', function(f) {
     console.dir(f);
  }); 

Which got triggered, but I was unsuccesful in getting the data. Googled a bit, and decided to ask here before getting messy with hidden textareas :)

coderofsalvation commented 9 years ago

nvm, just solved my problem using the following hack:

readline.js: added public function addText()

  + }
  + addText: function(str) {
  + //_line.text = str;
  + //_line.cursor = str.length+1;
  + //self.refresh();
  + _readline.addText(str);
  +  self.refresh();
  + }
};

function id(id) {
  return "#"+id;
}

onDomReady(): allow copy/paste

  $("*").pastableNonInputable();
  $("*").on('pasteText', function(ev, data) {
     console.dir(data);
     shell.addText(data.text);
  }); 

using paste.js

boom! as said its a hack..but it works for me on chrome

sdether commented 9 years ago

Interesting. So addText is just a function added to readline to be able to add text outside of its key event loop?

coderofsalvation commented 9 years ago

exactly. Personally I could not find a (public) readline function which does that. (Doesnt mean there isnt any) Pasting text directly to the DOM resulted in readline erasing the paste, to simply redraw the readline buffer.

On Mon, Mar 16, 2015 at 5:07 PM, Arne Claassen notifications@github.com wrote:

Interesting. So addText is just a function added to readline to be able to add text outside of its key event loop?

— Reply to this email directly or view it on GitHub https://github.com/sdether/josh.js/issues/28#issuecomment-81764646.

sdether commented 9 years ago

Yeah, there isn't such a facility, since readline really was just an event processor. I think what you did makes sense and I'll take a look whether i can take that it verbatim, or if there some other things it should do. Haven't looked at the processing loop in a while

coderofsalvation commented 9 years ago

I see thank you for your thoughts. Maybe there's a way to decorate readline with a public function without having to edit readline.js . I'll let you know when I discover something new.

On Mon, Mar 16, 2015 at 9:06 PM, Arne Claassen notifications@github.com wrote:

Yeah, there isn't such a facility, since readline really was just an event processor. I think what you did makes sense and I'll take a look whether i can take that it verbatim, or if there some other things it should do. Haven't looked at the processing loop in a while

— Reply to this email directly or view it on GitHub https://github.com/sdether/josh.js/issues/28#issuecomment-81908343.