Insert quotes at caret position; replace text selection with quotes; fix an old bug. Close #24

This commit is contained in:
Nicolas Stepien 2011-12-06 20:10:05 +01:00
parent ea4c581d2a
commit 667cb36461
3 changed files with 14 additions and 5 deletions

View File

@ -1658,15 +1658,17 @@
text = ">>" + id + "\n"; text = ">>" + id + "\n";
selection = window.getSelection(); selection = window.getSelection();
if (s = selection.toString()) { 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) { if (selectionID === id) {
s = s.replace(/\n/g, '\n>'); s = s.replace(/\n/g, '\n>');
text += ">" + s + "\n"; text += ">" + s + "\n";
} }
} }
ta = $('textarea', qr.el); ta = $('textarea', qr.el);
ta.value = ta.value.slice(0, ta.selectionStart) + text + ta.value.slice(ta.selectionEnd, ta.value.length);
ta.focus(); ta.focus();
return ta.value += text; ta.selectionEnd = ta.selectionStart + text.length;
return window.getSelection().collapseToEnd();
}, },
refresh: function() { refresh: function() {
var m, newFile, oldFile, _ref; var m, newFile, oldFile, _ref;

View File

@ -1,4 +1,7 @@
master master
- mayhem
quotes are now inserted at the caret position in the QR
quotes also replace the text selection in the QR
- aeosynth - aeosynth
update the captcha caching expiration date to 30mins update the captcha caching expiration date to 30mins

View File

@ -1295,14 +1295,18 @@ qr =
selection = window.getSelection() selection = window.getSelection()
if s = selection.toString() if s = selection.toString()
selectionID = $.x('preceding::input[@type="checkbox"][1]', selection.anchorNode)?.name selectionID = $.x('ancestor::blockquote', selection.anchorNode)?.parentNode.firstElementChild.name
if selectionID == id if selectionID is id
s = s.replace /\n/g, '\n>' s = s.replace /\n/g, '\n>'
text += ">#{s}\n" text += ">#{s}\n"
ta = $ 'textarea', qr.el 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.focus()
ta.value += text #move the caret to the end of the new quote
ta.selectionEnd = ta.selectionStart + text.length
window.getSelection().collapseToEnd()
refresh: -> refresh: ->
$('[name=sub]', qr.el).value = '' $('[name=sub]', qr.el).value = ''