insert text at cursor

This commit is contained in:
James Campos 2011-09-01 02:42:01 -07:00
parent 4225a7dfdf
commit dfd226bd64
2 changed files with 24 additions and 2 deletions

View File

@ -1253,8 +1253,20 @@
return $.bind(quote, 'click', QR.quote);
},
quote: function(e) {
var i, ss, ta, text, v;
e.preventDefault();
return QR.dialog(">>" + this.textContent + "\n");
text = ">>" + this.textContent + "\n";
if (!QR.el) {
QR.dialog(text);
return;
}
ta = $('textarea', QR.el);
v = ta.value;
ss = ta.selectionStart;
ta.value = v.slice(0, ss) + text + v.slice(ss);
i = ss + text.length;
ta.setSelectionRange(i, i);
return ta.focus();
},
dialog: function(text) {
var l, ta;

View File

@ -984,7 +984,17 @@ QR =
$.bind quote, 'click', QR.quote
quote: (e) ->
e.preventDefault()
QR.dialog ">>#{@textContent}\n"
text = ">>#{@textContent}\n"
if not QR.el
QR.dialog text
return
ta = $ 'textarea', QR.el
v = ta.value
ss = ta.selectionStart
ta.value = v[0...ss] + text + v[ss..]
i = ss + text.length
ta.setSelectionRange i, i
ta.focus()
dialog: (text='') ->
QR.el = ui.dialog 'qr', top: '0', left: '0', "
<a class=close title=close>X</a><input type=checkbox id=autohide title=autohide>