mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: quote whote post should insert at cursor position
This commit is contained in:
@@ -39,7 +39,34 @@ export default DiscourseController.extend({
|
||||
|
||||
// Import a quote from the post
|
||||
importQuote: function() {
|
||||
this.get('model').importQuote();
|
||||
var postStream = this.get('topic.postStream'),
|
||||
postId = this.get('model.post.id');
|
||||
|
||||
// If there is no current post, use the first post id from the stream
|
||||
if (!postId && postStream) {
|
||||
postId = postStream.get('firstPostId');
|
||||
}
|
||||
|
||||
// If we're editing a post, fetch the reply when importing a quote
|
||||
if (this.get('model.editingPost')) {
|
||||
var replyToPostNumber = this.get('model.post.reply_to_post_number');
|
||||
if (replyToPostNumber) {
|
||||
var replyPost = postStream.get('posts').findBy('post_number', replyToPostNumber);
|
||||
if (replyPost) {
|
||||
postId = replyPost.get('id');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (postId) {
|
||||
this.set('model.loading', true);
|
||||
var composer = this;
|
||||
return Discourse.Post.load(postId).then(function(post) {
|
||||
var quote = Discourse.Quote.build(post, post.get("raw"))
|
||||
composer.appendBlockAtCursor(quote);
|
||||
composer.set('model.loading', false);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
cancel: function() {
|
||||
|
||||
@@ -328,36 +328,6 @@ Discourse.Composer = Discourse.Model.extend({
|
||||
Discourse.KeyValueStore.set({ key: 'composer.showPreview', value: this.get('showPreview') });
|
||||
},
|
||||
|
||||
importQuote: function() {
|
||||
var postStream = this.get('topic.postStream'),
|
||||
postId = this.get('post.id');
|
||||
|
||||
if (!postId && postStream) {
|
||||
postId = postStream.get('firstPostId');
|
||||
}
|
||||
|
||||
// If we're editing a post, fetch the reply when importing a quote
|
||||
if (this.get('editingPost')) {
|
||||
var replyToPostNumber = this.get('post.reply_to_post_number');
|
||||
if (replyToPostNumber) {
|
||||
var replyPost = postStream.get('posts').findBy('post_number', replyToPostNumber);
|
||||
if (replyPost) {
|
||||
postId = replyPost.get('id');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If there is no current post, use the post id from the stream
|
||||
if (postId) {
|
||||
this.set('loading', true);
|
||||
var composer = this;
|
||||
return Discourse.Post.load(postId).then(function(post) {
|
||||
composer.appendText(Discourse.Quote.build(post, post.get('raw')));
|
||||
composer.set('loading', false);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/*
|
||||
Open a composer
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ window.PagedownCustom = {
|
||||
id: 'wmd-quote-post',
|
||||
description: I18n.t("composer.quote_post_title"),
|
||||
execute: function() {
|
||||
// AWFUL but I can't figure out how to call a controller method from outside our app
|
||||
return Discourse.__container__.lookup('controller:composer').send('importQuote');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user