From 0c56b42f37bb555f03a9eb149565da9800e4a1b9 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Tue, 6 Dec 2011 21:33:31 +0100 Subject: [PATCH] Fix last Firefox issue. --- 4chan_x.user.js | 7 ++++--- script.coffee | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 8d92b64c1..a47dcbd4e 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1647,7 +1647,7 @@ return false; }, quote: function(e) { - var id, s, selection, selectionID, ta, text, _ref; + var caretPos, id, s, selection, selectionID, ta, text, _ref; if (e) e.preventDefault(); if (qr.el) { $('#autohide', qr.el).checked = false; @@ -1665,9 +1665,10 @@ } } ta = $('textarea', qr.el); - ta.value = ta.value.slice(0, ta.selectionStart) + text + ta.value.slice(ta.selectionEnd, ta.value.length); + caretPos = ta.selectionStart; + ta.value = ta.value.slice(0, caretPos) + text + ta.value.slice(ta.selectionEnd, ta.value.length); ta.focus(); - return ta.selectionStart = ta.selectionEnd = ta.selectionStart + text.length; + return ta.selectionStart = ta.selectionEnd = caretPos + text.length; }, refresh: function() { var m, newFile, oldFile, _ref; diff --git a/script.coffee b/script.coffee index afe6120dd..af69c225b 100644 --- a/script.coffee +++ b/script.coffee @@ -1301,11 +1301,12 @@ qr = text += ">#{s}\n" ta = $ 'textarea', qr.el + caretPos = ta.selectionStart #replace selection for text - ta.value = ta.value.slice(0, ta.selectionStart) + text + ta.value.slice(ta.selectionEnd, ta.value.length) + ta.value = ta.value.slice(0, caretPos) + text + ta.value.slice(ta.selectionEnd, ta.value.length) ta.focus() #move the caret to the end of the new quote - ta.selectionStart = ta.selectionEnd = ta.selectionStart + text.length + ta.selectionStart = ta.selectionEnd = caretPos + text.length refresh: -> $('[name=sub]', qr.el).value = ''