Skip to content

Commit

Permalink
[feature] restore scrollTop offset for session-container based on vie…
Browse files Browse the repository at this point in the history
…w state
  • Loading branch information
ReDEnergy committed Apr 26, 2018
1 parent 2fba61d commit b3bcc1c
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 15 deletions.
3 changes: 3 additions & 0 deletions data/scripts/components/session-bookmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,9 @@ define(function(require, exports) {
// ------------------------------------------------------------------------
// Init Code Events

container.addEventListener('scroll', function () {
AppConfig.set('state.scrollTop.' + SyncModel.state.session, container.scrollTop);
});
container.addEventListener('contextmenu', bookmarkContextMenu);
container.addEventListener('mousedown', bookmarkMouseDown);

Expand Down
19 changes: 17 additions & 2 deletions data/scripts/components/session-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ define(function(require, exports) {
var sessionTab = new SessionTab(document, tab, 0, -1);
DOMBookmarks.appendChild(sessionTab.DOMRoot);
});

this.restoreScrollTop('current');
}
else
{
Expand Down Expand Up @@ -250,13 +252,17 @@ define(function(require, exports) {
windowIndex++;
}
}
});

this.restoreScrollTop('current');
}.bind(this));
}
});
}.bind(this));
};

SessionContainer.prototype.showHistorySession = function showHistorySession(sessionInfo)
{
var newSession = (this.selectedHistorySession != undefined) && (this.selectedHistorySession != sessionInfo);

this.setUIState('history', (new Date(sessionInfo.lastSave)).toLocaleString(), -1);
this.selectedHistorySession = sessionInfo;

Expand Down Expand Up @@ -284,6 +290,8 @@ define(function(require, exports) {

windowIndex++;
}

this.restoreScrollTop('history', newSession ? 0 : undefined);
};

SessionContainer.prototype.previewSession = function previewSession(sessionID)
Expand All @@ -307,10 +315,17 @@ define(function(require, exports) {
}

this.updateSessionInfo();
this.restoreScrollTop('restore');

}.bind(this));
};

SessionContainer.prototype.restoreScrollTop = function restoreScrollTop(state, forcedValue)
{
var scrollTop = AppConfig.get('state.scrollTop.' + state);
this.DOMBookmarks.scrollTop = (forcedValue !== undefined) ? forcedValue : scrollTop;
};

SessionContainer.prototype.bookmarkCurrentTab = function bookmarkCurrentTab()
{
// Test if already saved in this session
Expand Down
2 changes: 1 addition & 1 deletion data/scripts/components/session-folder.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ define(function(require, exports) {
if (bookmarkContext.bookmarkID == sessionID)
{
if (!DragContext.hasContext()) {
SessionList.selectSession(bookmarkContext, false);
SessionList.selectSyncSession(bookmarkContext, false);
}
}
else
Expand Down
27 changes: 20 additions & 7 deletions data/scripts/components/session-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,23 @@ define(function(require, exports) {
}.bind(this));

WindowEvents.on(document, 'ShowCurrentSession', function() {
AppConfig.set('session.selected', undefined);
if (AppConfig.get('session.selected') != null) {
AppConfig.set('session.selected', null);
AppConfig.set('state.scrollTop.current', 0);
}
this.setState('active');
this.setSelectedNode(undefined);
}.bind(this));

WindowEvents.on(document, 'ShowSyncList', function(options) {
// Select first visible session
if (this.promiseInfo.sessionID == undefined)
if (this.promiseInfo.sessionID == null)
{
for (var i=0; i < this.sessions.length; i++)
{
if (this.sessions[i].isVisible())
{
this.selectSession(this.sessions[i], true, false);
this.selectSyncSession(this.sessions[i], true, false);
break;
}
}
Expand Down Expand Up @@ -204,8 +207,13 @@ define(function(require, exports) {
{
this.setSelectedNode(node);
var index = node.getAttribute('index') | 0;

SessionHistory.getHistory(function (sessions) {
AppConfig.set('session.history.selected', index);
if (AppConfig.get('session.history.selected') != index) {
AppConfig.set('session.history.selected', index);
AppConfig.set('state.scrollTop.history', 0);
}

WindowEvents.emit(document, 'ShowHistorySession', sessions[index]);
});
}.bind(this);
Expand Down Expand Up @@ -310,7 +318,7 @@ define(function(require, exports) {
// Preview the selected session if available
if (selectedSession)
{
this.selectSession(selectedSession, true, AppConfig.isInitState());
this.selectSyncSession(selectedSession, true, AppConfig.isInitState());
return;
}

Expand Down Expand Up @@ -342,9 +350,14 @@ define(function(require, exports) {
}
};

SessionList.prototype.selectSession = function selectSession(selectedSession, scrollTo, snap)
SessionList.prototype.selectSyncSession = function selectSyncSession(selectedSession, scrollTo, snap)
{
AppConfig.set('session.selected', selectedSession.bookmarkID);
if (AppConfig.get('session.selected') != selectedSession.bookmarkID)
{
AppConfig.set('session.selected', selectedSession.bookmarkID);
AppConfig.set('state.scrollTop.restore', 0);
}

this.setSelectedNode(selectedSession.DOMRoot);

WindowEvents.emit(this.document, 'ViewSession', selectedSession.bookmarkID);
Expand Down
10 changes: 7 additions & 3 deletions data/scripts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ define(function(require, exports) {
getConfigValue('style.scale.sessions', 12);
getConfigValue('style.scale.bookmarks', 14);

getConfigValue('state.scrollTop.current', 0);
getConfigValue('state.scrollTop.restore', 0);
getConfigValue('state.scrollTop.history', 0);

// Session saving settings
getConfigValue('session.save', {
pinned: false,
Expand All @@ -55,8 +59,8 @@ define(function(require, exports) {
getConfigValue('session.view', undefined);
getConfigValue('session.sorting', 'position-asc');
getConfigValue('session.active.filter', '');
getConfigValue('session.selected', undefined);
getConfigValue('session.history.selected', undefined);
getConfigValue('session.selected', null);
getConfigValue('session.history.selected', null);

// Bookmarks configuration
getConfigValue('bookmark.click.new.tab', false);
Expand Down Expand Up @@ -86,7 +90,7 @@ define(function(require, exports) {

var get = function get(key)
{
if (localSettings[key] == undefined) {
if (localSettings[key] === undefined) {
console.log('[ERROR] Settings key [' + key + '] was not found!');
}
return localSettings[key];
Expand Down
4 changes: 2 additions & 2 deletions scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,5 @@ var WindowUtils = (function ()
// Delete previous undo events
browser.storage.local.set({'undo.events' : []});
browser.storage.local.set({'session.active.filter' : ''});
browser.storage.local.set({'session.selected' : undefined});
browser.storage.local.set({'session.history.selected' : undefined});
browser.storage.local.set({'session.selected' : null});
browser.storage.local.set({'session.history.selected' : null});

0 comments on commit b3bcc1c

Please sign in to comment.