From f28bfd4e7ec6e69fc3982c2f1d1728b755280cd1 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 13 Dec 2012 12:00:17 +0100 Subject: [PATCH] Fix #853 --- 4chan_x.user.js | 10 ++-------- changelog | 2 ++ script.coffee | 9 +++------ 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index 4e2b31cfb..132b85c04 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1991,23 +1991,17 @@ } id = this.previousSibling.hash.slice(2); text = ">>" + id + "\n"; - sel = window.getSelection(); + sel = d.getSelection(); if ((s = sel.toString().trim()) && id === ((_ref = $.x('ancestor-or-self::blockquote', sel.anchorNode)) != null ? _ref.id.match(/\d+$/)[0] : void 0)) { - if ($.engine === 'presto') { - s = d.getSelection().trim(); - } s = s.replace(/\n/g, '\n>'); text += ">" + s + "\n"; } ta = $('textarea', QR.el); caretPos = ta.selectionStart; ta.value = ta.value.slice(0, caretPos) + text + ta.value.slice(ta.selectionEnd); - ta.focus(); range = caretPos + text.length; - if ($.engine === 'presto') { - range += text.match(/\n/g).length; - } ta.setSelectionRange(range, range); + ta.focus(); return $.event(ta, new Event('input')); }, characterCount: function() { diff --git a/changelog b/changelog index 3c64215f6..055026b08 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,6 @@ master +- Mayhem + Fix selection quoting on Opera. 2.37.0 - noface diff --git a/script.coffee b/script.coffee index b29899db7..29f182e2d 100644 --- a/script.coffee +++ b/script.coffee @@ -1552,10 +1552,9 @@ QR = id = @previousSibling.hash[2..] text = ">>#{id}\n" - sel = window.getSelection() + sel = d.getSelection() if (s = sel.toString().trim()) and id is $.x('ancestor-or-self::blockquote', sel.anchorNode)?.id.match(/\d+$/)[0] - # XXX Opera needs d.getSelection() to retain linebreaks from the selected text - s = d.getSelection().trim() if $.engine is 'presto' + # XXX Opera doesn't retain `\n`s? s = s.replace /\n/g, '\n>' text += ">#{s}\n" @@ -1563,12 +1562,10 @@ QR = caretPos = ta.selectionStart # Replace selection for text. ta.value = ta.value[...caretPos] + text + ta.value[ta.selectionEnd..] - ta.focus() # Move the caret to the end of the new quote. range = caretPos + text.length - # XXX Opera counts newlines as double - range += text.match(/\n/g).length if $.engine is 'presto' ta.setSelectionRange range, range + ta.focus() # Fire the 'input' event $.event ta, new Event 'input'