From 0b26a4d81715a2c51eb053fea45fd0e1a14d32c7 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Fri, 15 Jun 2012 18:05:21 +0200 Subject: [PATCH] Fine text selection to quote on Opera. --- 4chan_x.user.js | 5 ++++- script.coffee | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index a069e0ed6..90359ecd1 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1562,6 +1562,9 @@ text = ">>" + id + "\n"; sel = window.getSelection(); if ((s = sel.toString()) && id === ((_ref = $.x('ancestor-or-self::blockquote', sel.anchorNode)) != null ? _ref.id.match(/\d+$/)[0] : void 0)) { + if ($.engine === 'presto') { + s = d.getSelection(); + } s = s.replace(/\n/g, '\n>'); text += ">" + s + "\n"; } @@ -1571,7 +1574,7 @@ ta.focus(); range = caretPos + text.length; if ($.engine === 'presto') { - range++; + range += text.match(/\n/g).length; } ta.setSelectionRange(range, range); e = d.createEvent('Event'); diff --git a/script.coffee b/script.coffee index 3ddaadb87..0a69e51db 100644 --- a/script.coffee +++ b/script.coffee @@ -1145,6 +1145,8 @@ QR = sel = window.getSelection() if (s = sel.toString()) 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() if $.engine is 'presto' s = s.replace /\n/g, '\n>' text += ">#{s}\n" @@ -1156,7 +1158,7 @@ QR = # Move the caret to the end of the new quote. range = caretPos + text.length # XXX Opera counts newlines as double - range++ if $.engine is 'presto' + range += text.match(/\n/g).length if $.engine is 'presto' ta.setSelectionRange range, range # Fire the 'input' event