Don't debouce `afterRender`, debounce the preview refreshing mechanism.
This commit is contained in:
parent
9a24d2651d
commit
f9243a10cc
|
@ -48,22 +48,24 @@ Discourse.ComposerView = Discourse.View.extend(Ember.Evented, {
|
||||||
return this.present('controller.createdPost') ? 'created-post' : null;
|
return this.present('controller.createdPost') ? 'created-post' : null;
|
||||||
}.property('model.createdPost'),
|
}.property('model.createdPost'),
|
||||||
|
|
||||||
observeReplyChanges: function() {
|
|
||||||
var self = this;
|
refreshPreview: Discourse.debounce(function() {
|
||||||
if (this.get('model.hidePreview')) return;
|
if (this.editor) {
|
||||||
Ember.run.next(function() {
|
this.editor.refreshPreview();
|
||||||
if (self.editor) {
|
// if the caret is on the last line ensure preview scrolled to bottom
|
||||||
self.editor.refreshPreview();
|
var caretPosition = Discourse.Utilities.caretPosition(this.wmdInput[0]);
|
||||||
// if the caret is on the last line ensure preview scrolled to bottom
|
if (!this.wmdInput.val().substring(caretPosition).match(/\n/)) {
|
||||||
var caretPosition = Discourse.Utilities.caretPosition(self.wmdInput[0]);
|
var $wmdPreview = $('#wmd-preview');
|
||||||
if (!self.wmdInput.val().substring(caretPosition).match(/\n/)) {
|
if ($wmdPreview.is(':visible')) {
|
||||||
var $wmdPreview = $('#wmd-preview');
|
$wmdPreview.scrollTop($wmdPreview[0].scrollHeight);
|
||||||
if ($wmdPreview.is(':visible')) {
|
|
||||||
$wmdPreview.scrollTop($wmdPreview[0].scrollHeight);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
}, 30),
|
||||||
|
|
||||||
|
observeReplyChanges: function() {
|
||||||
|
if (this.get('model.hidePreview')) return;
|
||||||
|
Ember.run.scheduleOnce('afterRender', this, 'refreshPreview');
|
||||||
}.observes('model.reply', 'model.hidePreview'),
|
}.observes('model.reply', 'model.hidePreview'),
|
||||||
|
|
||||||
movePanels: function(sizePx) {
|
movePanels: function(sizePx) {
|
||||||
|
@ -131,7 +133,7 @@ Discourse.ComposerView = Discourse.View.extend(Ember.Evented, {
|
||||||
},
|
},
|
||||||
|
|
||||||
// Called after the preview renders. Debounced for performance
|
// Called after the preview renders. Debounced for performance
|
||||||
afterRender: Discourse.debounce(function() {
|
afterRender: function() {
|
||||||
var $wmdPreview = $('#wmd-preview');
|
var $wmdPreview = $('#wmd-preview');
|
||||||
if ($wmdPreview.length === 0) return;
|
if ($wmdPreview.length === 0) return;
|
||||||
|
|
||||||
|
@ -156,7 +158,7 @@ Discourse.ComposerView = Discourse.View.extend(Ember.Evented, {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.trigger('previewRefreshed', $wmdPreview);
|
this.trigger('previewRefreshed', $wmdPreview);
|
||||||
}, 100),
|
},
|
||||||
|
|
||||||
initEditor: function() {
|
initEditor: function() {
|
||||||
// not quite right, need a callback to pass in, meaning this gets called once,
|
// not quite right, need a callback to pass in, meaning this gets called once,
|
||||||
|
|
Loading…
Reference in New Issue