From c2c4eff08be0e17172edc4edbb71641ef10f3b2f Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 26 Feb 2016 11:37:37 -0500 Subject: [PATCH] FIX: Quirky scrolling position with keyboard use --- .../discourse/components/mount-widget.js.es6 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/assets/javascripts/discourse/components/mount-widget.js.es6 b/app/assets/javascripts/discourse/components/mount-widget.js.es6 index bfadbd059f9..869e4a0ec72 100644 --- a/app/assets/javascripts/discourse/components/mount-widget.js.es6 +++ b/app/assets/javascripts/discourse/components/mount-widget.js.es6 @@ -59,7 +59,23 @@ export default Ember.Component.extend({ newTree._emberView = this; const patches = diff(this._tree || this._rootNode, newTree); + + const $body = $(document); + const prevHeight = $body.height(); + const prevScrollTop = $body.scrollTop(); + this._rootNode = patch(this._rootNode, patches); + + const height = $body.height(); + const scrollTop = $body.scrollTop(); + + // This hack is for when swapping out many cloaked views at once + // when using keyboard navigation. It could suddenly move the + // scroll + if (prevHeight === height && scrollTop !== prevScrollTop) { + $body.scrollTop(prevScrollTop); + } + this._tree = newTree; if (this._afterRender) {