operating system cut and paste for google chrome.

48 views
Skip to first unread message

Joe

unread,
Feb 11, 2010, 1:48:20 AM2/11/10
to Ymacs - AJAX code editor
This is one ugly hack, and right now it only works for google chrome
(and maybe safari), but I have ctrl-C/ctrl-V cut and paste working for
ymacs.

In index.html I added right after the body tag:
<div id="clipout" style="white-space: pre;height:1px;width:
1px;overflow:hidden;"></div>

<script>
inpaste = false;
function pasteIn() {
var c = document.getElementById('clipin');
var v = c.value;
document.body.removeChild(c);

if (v.length > 0) {
var b = window.ymacs.getActiveBuffer();
b._insertText(v);
b.cmd("yank");
}
inpaste = false;
return false;
}
</script>


In ymacs-frame.js at the top of the P._on_keyDown = function(ev) {
I added:

if (ev.which === 86) { // ctrl-V
if(document.getElementById('clipin')) {
pasteIn();
ev.stopDomEvent();
return false;
}
var n = document.createElement('textarea');
n.id = 'clipin';
n.onkeyup = pasteIn;
document.body.appendChild(n);
n.focus();
return true;
}

if (ev.which === 67) { // ctrl-C
var str = this.buffer.cmd("buffer_substring");
if(str.length < 1) { return true;}

var clipout = document.getElementById('clipout');
clipout.innerHTML = str;
var s = window.getSelection();
var r1 = document.createRange();
r1.setStartBefore(clipout);
r1.setEndAfter(clipout);
s.addRange(r1);
return true;
}

and I think that's it. it's working OK for me.
I'm sure there is probably a *much* better way to do it, but this will
get me by for now.

-joe


Reply all
Reply to author
Forward
0 new messages