From 74a454c203a97468ee7d6772d107d9d0b9b341a1 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 2 Jun 2016 13:50:12 -0400 Subject: [PATCH] FIX: Lock keyboard controls for navigating posts to eyeline --- .../components/scrolling-post-stream.js.es6 | 6 +++--- .../discourse/lib/keyboard-shortcuts.js.es6 | 12 ++++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/discourse/components/scrolling-post-stream.js.es6 b/app/assets/javascripts/discourse/components/scrolling-post-stream.js.es6 index b2cf0119dd1..2ee09d5be26 100644 --- a/app/assets/javascripts/discourse/components/scrolling-post-stream.js.es6 +++ b/app/assets/javascripts/discourse/components/scrolling-post-stream.js.es6 @@ -93,7 +93,6 @@ export default MountWidget.extend({ // $('.debug-eyeline').css({ height: '1px', width: '100%', backgroundColor: 'blue', position: 'absolute', top: `${topCheck}px` }); let allAbove = true; - let bottomView = topView; while (bottomView < $posts.length) { const post = $posts[bottomView]; @@ -160,7 +159,8 @@ export default MountWidget.extend({ this.sendAction('bottomVisibleChanged', { post: last, refresh }); } - if (this._currentPost !== currentPost) { + const changedPost = this._currentPost !== currentPost; + if (changedPost) { this._currentPost = currentPost; const post = posts.objectAt(currentPost); this.sendAction('currentPostChanged', { post }); @@ -169,7 +169,7 @@ export default MountWidget.extend({ if (percent !== null) { if (percent > 1.0) { percent = 1.0; } - if (this._currentPercent !== percent) { + if (changedPost || (this._currentPercent !== percent)) { this._currentPercent = percent; this.sendAction('currentPostScrolled', { percent }); } diff --git a/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6 b/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6 index 8caebdfad22..9ef9f2e1709 100644 --- a/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6 +++ b/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6 @@ -1,5 +1,6 @@ import DiscourseURL from 'discourse/lib/url'; import Composer from 'discourse/models/composer'; +import { scrollTopFor } from 'discourse/lib/offset-calculator'; const bindings = { '!': {postAction: 'showFlags'}, @@ -298,12 +299,19 @@ export default { if ($article.is('.topic-post')) { $('a.tabLoc', $article).focus(); - } + this._scrollToPost($article); - this._scrollList($article, direction); + } else { + this._scrollList($article, direction); + } } }, + _scrollToPost($article) { + const pos = $article.offset(); + $(window).scrollTop(Math.ceil(pos.top - scrollTopFor(pos.top))); + }, + _scrollList($article) { // Try to keep the article on screen const pos = $article.offset();