summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2018-11-19 09:37:45 +0100
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2018-11-19 09:53:21 +0100
commitbc801489fbb72fec5db72e5bd0d7aa3ac8d822fb (patch)
tree3282e7a4be7df86e6511c362e98efb78d51889fc
parent0ca53189c638f8c451fc1cefb7540fb9a2ae958e (diff)
Fix the scroll position of the chat view in the sidebar
When the chat view was in the sidebar, the scroll position of the chat view was reset to the top every time that the sidebar was closed and opened again or the chat tab was selected after changing to a different one. The reason is that detaching an element and attaching it again, which happens in both scenarios, resets the scroll position of the element, so now the scroll position is explicitly saved before closing the sidebar or unselecting the chat tab and restored again after opening the sidebar or selecting the chat tab again. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
-rw-r--r--js/app.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/js/app.js b/js/app.js
index 312fb22d1..3680f752f 100644
--- a/js/app.js
+++ b/js/app.js
@@ -631,6 +631,46 @@
this._chatView.focusChatInput();
}.bind(this));
+ // Opening and closing the sidebar detachs its contents to perform
+ // the animation; detaching an element and attaching it again resets
+ // its scroll position, so the scroll position of the chat view
+ // needs to be saved before the sidebar is closed and restored again
+ // once the sidebar is opened.
+ this._chatView.listenTo(this._sidebarView, 'opened', function() {
+ if (this._sidebarView.getCurrentTabId() !== 'chat') {
+ return;
+ }
+
+ this._chatView.restoreScrollPosition();
+ }.bind(this));
+ this._chatView.listenTo(this._sidebarView, 'close', function() {
+ if (this._sidebarView.getCurrentTabId() !== 'chat') {
+ return;
+ }
+
+ this._chatView.saveScrollPosition();
+ }.bind(this));
+
+ // Selecting a different tab detachs the contents of the previous
+ // tab and attachs the contents of the new tab; detaching an element
+ // and attaching it again resets its scroll position, so the scroll
+ // position of the chat view needs to be saved when the chat tab is
+ // unselected and restored again when the chat tab is selected.
+ this._chatView.listenTo(this._sidebarView, 'unselect:tab', function(tabId) {
+ if (tabId !== 'chat') {
+ return;
+ }
+
+ this._chatView.saveScrollPosition();
+ }.bind(this));
+ this._chatView.listenTo(this._sidebarView, 'select:tab', function(tabId) {
+ if (tabId !== 'chat') {
+ return;
+ }
+
+ this._chatView.restoreScrollPosition();
+ }.bind(this));
+
this._messageCollection.listenTo(roomChannel, 'leaveCurrentRoom', function() {
this.stopReceivingMessages();
});