From ad3e363bf2eadca59c6f80114a623f5e65f48b8d Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 2 Feb 2012 21:42:05 +0100 Subject: [PATCH] Small refactor. --- 4chan_x.user.js | 6 ++---- script.coffee | 10 +++++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 0ac1abb5a..3c0a62ea3 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1349,11 +1349,9 @@ } ta = $('textarea', qr.el); caretPos = ta.selectionStart; - ta.value = ta.value.slice(0, caretPos) + text + ta.value.slice(ta.selectionEnd, ta.value.length); + qr.selected.el.lastChild.textContent = qr.selected.com = ta.value = ta.value.slice(0, caretPos) + text + ta.value.slice(ta.selectionEnd, ta.value.length); ta.focus(); - ta.selectionEnd = ta.selectionStart = caretPos + text.length; - qr.selected.com = ta.value; - return qr.selected.el.lastChild.textContent = ta.value; + return ta.selectionEnd = ta.selectionStart = caretPos + text.length; }, fileDrop: function(e) { if (/TEXTAREA|INPUT/.test(e.target.nodeName)) return; diff --git a/script.coffee b/script.coffee index b4d5d4116..dcd1862fe 100644 --- a/script.coffee +++ b/script.coffee @@ -983,15 +983,15 @@ qr = ta = $ 'textarea', qr.el caretPos = ta.selectionStart # Replace selection for text. - ta.value = ta.value[0...caretPos] + text + ta.value[ta.selectionEnd...ta.value.length] + # onchange event isn't triggered, save value. + qr.selected.el.lastChild.textContent = + qr.selected.com = + ta.value = + ta.value[0...caretPos] + text + ta.value[ta.selectionEnd...ta.value.length] ta.focus() # Move the caret to the end of the new quote. ta.selectionEnd = ta.selectionStart = caretPos + text.length - # onchange event isn't triggered, save value. - qr.selected.com = ta.value - qr.selected.el.lastChild.textContent = ta.value - fileDrop: (e) -> return if /TEXTAREA|INPUT/.test e.target.nodeName e.preventDefault()