diff --git a/4chan_x.user.js b/4chan_x.user.js
index 08bc41aa8..6d48387c7 100644
--- a/4chan_x.user.js
+++ b/4chan_x.user.js
@@ -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;
diff --git a/script.coffee b/script.coffee
index bfc97d2ef..c253856dc 100644
--- a/script.coffee
+++ b/script.coffee
@@ -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', "
X