From 667cb36461a5ed9a46e0c92c0fb7ac565dfda0ed Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Tue, 6 Dec 2011 20:10:05 +0100 Subject: [PATCH] Insert quotes at caret position; replace text selection with quotes; fix an old bug. Close #24 --- 4chan_x.user.js | 6 ++++-- changelog | 3 +++ script.coffee | 10 +++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/4chan_x.user.js b/4chan_x.user.js index fc0916eea..8ed9155e4 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1658,15 +1658,17 @@ text = ">>" + id + "\n"; selection = window.getSelection(); if (s = selection.toString()) { - selectionID = (_ref = $.x('preceding::input[@type="checkbox"][1]', selection.anchorNode)) != null ? _ref.name : void 0; + selectionID = (_ref = $.x('ancestor::blockquote', selection.anchorNode)) != null ? _ref.parentNode.firstElementChild.name : void 0; if (selectionID === id) { s = s.replace(/\n/g, '\n>'); text += ">" + s + "\n"; } } ta = $('textarea', qr.el); + ta.value = ta.value.slice(0, ta.selectionStart) + text + ta.value.slice(ta.selectionEnd, ta.value.length); ta.focus(); - return ta.value += text; + ta.selectionEnd = ta.selectionStart + text.length; + return window.getSelection().collapseToEnd(); }, refresh: function() { var m, newFile, oldFile, _ref; diff --git a/changelog b/changelog index a63d81432..5dab58ce4 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,7 @@ master +- mayhem + quotes are now inserted at the caret position in the QR + quotes also replace the text selection in the QR - aeosynth update the captcha caching expiration date to 30mins diff --git a/script.coffee b/script.coffee index 863d8646c..e1644c1bf 100644 --- a/script.coffee +++ b/script.coffee @@ -1295,14 +1295,18 @@ qr = selection = window.getSelection() if s = selection.toString() - selectionID = $.x('preceding::input[@type="checkbox"][1]', selection.anchorNode)?.name - if selectionID == id + selectionID = $.x('ancestor::blockquote', selection.anchorNode)?.parentNode.firstElementChild.name + if selectionID is id s = s.replace /\n/g, '\n>' text += ">#{s}\n" ta = $ 'textarea', qr.el + #replace selection for text + ta.value = ta.value.slice(0, ta.selectionStart) + text + ta.value.slice(ta.selectionEnd, ta.value.length) ta.focus() - ta.value += text + #move the caret to the end of the new quote + ta.selectionEnd = ta.selectionStart + text.length + window.getSelection().collapseToEnd() refresh: -> $('[name=sub]', qr.el).value = ''