Allow reply as new topic to use the selected text as a quote.

This commit is contained in:
Robin Ward 2014-05-16 12:19:56 -04:00
parent 4ca0a162b4
commit a2a07a9852
2 changed files with 28 additions and 21 deletions

View File

@ -217,19 +217,21 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
replyAsNewTopic: function(post) { replyAsNewTopic: function(post) {
var composerController = this.get('controllers.composer'), var composerController = this.get('controllers.composer'),
promise = composerController.open({ quoteController = this.get('controllers.quote-button'),
action: Discourse.Composer.CREATE_TOPIC, quotedText = Discourse.Quote.build(quoteController.get('post'), quoteController.get('buffer')),
draftKey: Discourse.Composer.REPLY_AS_NEW_TOPIC_KEY self = this;
}),
postUrl = "" + location.protocol + "//" + location.host + (post.get('url')),
postLink = "[" + (this.get('title')) + "](" + postUrl + ")";
promise.then(function() { quoteController.deselectText();
Discourse.Post.loadQuote(post.get('id')).then(function(q) {
composerController.appendText(I18n.t("post.continue_discussion", { composerController.open({
postLink: postLink action: Discourse.Composer.CREATE_TOPIC,
}) + "\n\n" + q); draftKey: Discourse.Composer.REPLY_AS_NEW_TOPIC_KEY
}); }).then(function() {
return Em.isEmpty(quotedText) ? Discourse.Post.loadQuote(post.get('id')) : quotedText;
}).then(function(q) {
var postUrl = "" + location.protocol + "//" + location.host + (post.get('url')),
postLink = "[" + self.get('title') + "](" + postUrl + ")";
composerController.appendText(I18n.t("post.continue_discussion", { postLink: postLink }) + "\n\n" + q);
}); });
}, },
@ -423,11 +425,10 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
// Post related methods // Post related methods
replyToPost: function(post) { replyToPost: function(post) {
var composerController = this.get('controllers.composer'); var composerController = this.get('controllers.composer'),
var quoteController = this.get('controllers.quote-button'); quoteController = this.get('controllers.quote-button'),
var quotedText = Discourse.Quote.build(quoteController.get('post'), quoteController.get('buffer')); quotedText = Discourse.Quote.build(quoteController.get('post'), quoteController.get('buffer')),
topic = post ? post.get('topic') : this.get('model');
var topic = post ? post.get('topic') : this.get('model');
quoteController.set('buffer', ''); quoteController.set('buffer', '');
@ -450,8 +451,9 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
opts.topic = topic; opts.topic = topic;
} }
var promise = composerController.open(opts); composerController.open(opts).then(function() {
promise.then(function() { composerController.appendText(quotedText); }); composerController.appendText(quotedText);
});
} }
return false; return false;
}, },

View File

@ -46,8 +46,13 @@ Discourse.QuoteButtonView = Discourse.View.extend({
$(document) $(document)
.on("mousedown.quote-button", function(e) { .on("mousedown.quote-button", function(e) {
view.set('isMouseDown', true); view.set('isMouseDown', true);
// we don't want to deselect when we click on the quote button or the reply button
if ($(e.target).hasClass('quote-button') || $(e.target).closest('.create').length > 0) return; var $target = $(e.target);
// we don't want to deselect when we click on buttons that use it
if ($target.hasClass('quote-button') ||
$target.closest('.create').length ||
$target.closest('.reply-new').length) return;
// deselects only when the user left click // deselects only when the user left click
// (allows anyone to `extend` their selection using shift+click) // (allows anyone to `extend` their selection using shift+click)
if (e.which === 1 && !e.shiftKey) controller.deselectText(); if (e.which === 1 && !e.shiftKey) controller.deselectText();