From 859c5db1f089f7ece73a3706e94b7ef4262cf72b Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Wed, 13 Feb 2013 16:57:32 +0100 Subject: [PATCH] Close #772. --- 4chan_x.user.js | 20 +++++++++++--------- changelog | 1 + src/qr.coffee | 25 +++++++++++++++++-------- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index a459c885f..4a01a2eca 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -4045,23 +4045,25 @@ } }, quote: function(e) { - var caretPos, post, range, s, sel, selectionRoot, ta, text; + var caretPos, post, range, s, sel, selectionRoot, ta, text, thread; if (e != null) { e.preventDefault(); } - QR.open(); - ta = $('textarea', QR.el); - if (QR.threadSelector && !ta.value && g.BOARD.ID !== 'f') { - QR.threadSelector.value = $.x('ancestor::div[parent::div[@class="board"]]', this).id.slice(1); - } - post = Get.postFromRoot($.x('ancestor-or-self::div[contains(@class,"postContainer")][1]', this)); - text = ">>" + post + "\n"; + text = ""; sel = d.getSelection(); - selectionRoot = $.x('ancestor-or-self::div[contains(@class,"postContainer")][1]', sel.anchorNode); + selectionRoot = $.x('ancestor::div[contains(@class,"postContainer")][1]', sel.anchorNode); + post = Get.postFromRoot($.x('ancestor::div[contains(@class,"postContainer")][1]', this)); + thread = g.BOARD.posts[Get.contextFromLink(this).thread]; if ((s = sel.toString().trim()) && post.nodes.root === selectionRoot) { s = s.replace(/\n/g, '\n>'); text += ">" + s + "\n"; } + text = !text && post === thread && (!QR.el || QR.el.hidden) ? "" : ">>" + post + "\n" + text; + QR.open(); + ta = $('textarea', QR.el); + if (QR.threadSelector && !ta.value && g.BOARD.ID !== 'f') { + QR.threadSelector.value = thread.ID; + } caretPos = ta.selectionStart; ta.value = ta.value.slice(0, caretPos) + text + ta.value.slice(ta.selectionEnd); range = caretPos + text.length; diff --git a/changelog b/changelog index ee00e0d90..24a2f9227 100644 --- a/changelog +++ b/changelog @@ -10,6 +10,7 @@ alpha QR changes: Creating threads outside of the index is now possible. Selection-to-quote also applies to selected text inside the post, not just inside the comment. + Quoting the OP will not insert the >>opnumber anymore unless the QR was already opened. Added touch and multi-touch support for dragging windows. The Thread Updater will pause when offline, and resume when online. Added Thread & Post Hiding in the Menu, with individual settings. diff --git a/src/qr.coffee b/src/qr.coffee index 1d04510b8..42428669a 100644 --- a/src/qr.coffee +++ b/src/qr.coffee @@ -219,21 +219,30 @@ QR = quote: (e) -> e?.preventDefault() - QR.open() - ta = $ 'textarea', QR.el - if QR.threadSelector and !ta.value and g.BOARD.ID isnt 'f' - QR.threadSelector.value = $.x('ancestor::div[parent::div[@class="board"]]', @).id[1..] - # Make sure we get the correct number, even with XXX censors - post = Get.postFromRoot $.x 'ancestor-or-self::div[contains(@class,"postContainer")][1]', @ - text = ">>#{post}\n" + text = "" sel = d.getSelection() - selectionRoot = $.x 'ancestor-or-self::div[contains(@class,"postContainer")][1]', sel.anchorNode + selectionRoot = $.x 'ancestor::div[contains(@class,"postContainer")][1]', sel.anchorNode + post = Get.postFromRoot $.x 'ancestor::div[contains(@class,"postContainer")][1]', @ + thread = g.BOARD.posts[Get.contextFromLink(@).thread] + if (s = sel.toString().trim()) and post.nodes.root is selectionRoot # XXX Opera doesn't retain `\n`s? s = s.replace /\n/g, '\n>' text += ">#{s}\n" + text = if !text and post is thread and (!QR.el or QR.el.hidden) + # Don't quote the OP unless the QR was already opened once. + "" + else + ">>#{post}\n#{text}" + + QR.open() + ta = $ 'textarea', QR.el + if QR.threadSelector and !ta.value and g.BOARD.ID isnt 'f' + QR.threadSelector.value = thread.ID + # Make sure we get the correct number, even with XXX censors + caretPos = ta.selectionStart # Replace selection for text. ta.value = ta.value[...caretPos] + text + ta.value[ta.selectionEnd..]