Unverified Commit 7f5413c7 authored by Robert Knight's avatar Robert Knight Committed by GitHub

Merge pull request #1932 from hypothesis/remove-invisible-threads

Remove "invisible threads" logic
parents 975feabb 75426f72
...@@ -37,16 +37,6 @@ function getThreadHeight(id) { ...@@ -37,16 +37,6 @@ function getThreadHeight(id) {
return elementHeight + marginHeight; return elementHeight + marginHeight;
} }
const virtualThreadOptions = {
// identify the thread types that need to be rendered
// but not actually visible to the user
invisibleThreadFilter: function(thread) {
// new highlights should always get rendered so we don't
// miss saving them via the render-save process
return thread.annotation.$highlight && metadata.isNew(thread.annotation);
},
};
// @ngInject // @ngInject
function ThreadListController($element, $scope, settings, store) { function ThreadListController($element, $scope, settings, store) {
// `visibleThreads` keeps track of the subset of all threads matching the // `visibleThreads` keeps track of the subset of all threads matching the
...@@ -66,12 +56,7 @@ function ThreadListController($element, $scope, settings, store) { ...@@ -66,12 +56,7 @@ function ThreadListController($element, $scope, settings, store) {
this.isThemeClean = settings.theme === 'clean'; this.isThemeClean = settings.theme === 'clean';
const options = Object.assign( const options = { scrollRoot: this.scrollRoot };
{
scrollRoot: this.scrollRoot,
},
virtualThreadOptions
);
let visibleThreads; let visibleThreads;
this.$onInit = () => { this.$onInit = () => {
...@@ -98,7 +83,6 @@ function ThreadListController($element, $scope, settings, store) { ...@@ -98,7 +83,6 @@ function ThreadListController($element, $scope, settings, store) {
function onVisibleThreadsChanged(state) { function onVisibleThreadsChanged(state) {
self.virtualThreadList = { self.virtualThreadList = {
visibleThreads: state.visibleThreads, visibleThreads: state.visibleThreads,
invisibleThreads: state.invisibleThreads,
offscreenUpperHeight: state.offscreenUpperHeight + 'px', offscreenUpperHeight: state.offscreenUpperHeight + 'px',
offscreenLowerHeight: state.offscreenLowerHeight + 'px', offscreenLowerHeight: state.offscreenLowerHeight + 'px',
}; };
......
...@@ -17,11 +17,6 @@ ...@@ -17,11 +17,6 @@
<hr ng-if="vm.isThemeClean" <hr ng-if="vm.isThemeClean"
class="thread-list__separator--theme-clean" /> class="thread-list__separator--theme-clean" />
</li> </li>
<li id="{{child.id}}"
ng-show="false"
ng-repeat="child in vm.virtualThreadList.invisibleThreads track by child.id">
<annotation-thread thread="child" />
</li>
<li class="thread-list__spacer" <li class="thread-list__spacer"
ng-style="{height: vm.virtualThreadList.offscreenLowerHeight}"></li> ng-style="{height: vm.virtualThreadList.offscreenLowerHeight}"></li>
</ul> </ul>
...@@ -4,9 +4,7 @@ import { $imports } from '../virtual-thread-list'; ...@@ -4,9 +4,7 @@ import { $imports } from '../virtual-thread-list';
describe('VirtualThreadList', function() { describe('VirtualThreadList', function() {
let lastState; let lastState;
let threadList; let threadList;
const threadOptions = { const threadOptions = {};
invisibleThreadFilter: null,
};
let fakeScope; let fakeScope;
let fakeScrollRoot; let fakeScrollRoot;
...@@ -95,7 +93,6 @@ describe('VirtualThreadList', function() { ...@@ -95,7 +93,6 @@ describe('VirtualThreadList', function() {
innerHeight: 100, innerHeight: 100,
}; };
threadOptions.invisibleThreadFilter = sinon.stub().returns(false);
threadOptions.scrollRoot = fakeScrollRoot; threadOptions.scrollRoot = fakeScrollRoot;
const rootThread = { annotation: undefined, children: [] }; const rootThread = { annotation: undefined, children: [] };
...@@ -145,19 +142,10 @@ describe('VirtualThreadList', function() { ...@@ -145,19 +142,10 @@ describe('VirtualThreadList', function() {
fakeScrollRoot.scrollTop = testCase.scrollOffset; fakeScrollRoot.scrollTop = testCase.scrollOffset;
fakeWindow.innerHeight = testCase.windowHeight; fakeWindow.innerHeight = testCase.windowHeight;
// make sure for everything that is not being presented in the
// visible viewport, we pass it to this function.
threadOptions.invisibleThreadFilter.returns(true);
threadList.setRootThread(thread); threadList.setRootThread(thread);
const visibleIDs = threadIDs(lastState.visibleThreads); const visibleIDs = threadIDs(lastState.visibleThreads);
const invisibleIDs = threadIDs(lastState.invisibleThreads);
assert.deepEqual(visibleIDs, testCase.expectedVisibleThreads); assert.deepEqual(visibleIDs, testCase.expectedVisibleThreads);
assert.equal(
invisibleIDs.length,
testCase.threads - testCase.expectedVisibleThreads.length
);
assert.equal( assert.equal(
lastState.offscreenUpperHeight, lastState.offscreenUpperHeight,
testCase.expectedHeightAbove testCase.expectedHeightAbove
......
...@@ -3,9 +3,6 @@ import EventEmitter from 'tiny-emitter'; ...@@ -3,9 +3,6 @@ import EventEmitter from 'tiny-emitter';
/** /**
* @typedef Options * @typedef Options
* @property {Function} [invisibleThreadFilter] - Function used to determine
* whether an off-screen thread should be rendered or not. Called with a
* `Thread` and if it returns `true`, the thread is rendered even if offscreen.
* @property {Element} [scrollRoot] - The scrollable Element which contains the * @property {Element} [scrollRoot] - The scrollable Element which contains the
* thread list. The set of on-screen threads is determined based on the scroll * thread list. The set of on-screen threads is determined based on the scroll
* position and height of this element. * position and height of this element.
...@@ -36,8 +33,6 @@ export default class VirtualThreadList extends EventEmitter { ...@@ -36,8 +33,6 @@ export default class VirtualThreadList extends EventEmitter {
this._rootThread = rootThread; this._rootThread = rootThread;
this._options = Object.assign({}, options);
// Cache of thread ID -> last-seen height // Cache of thread ID -> last-seen height
this._heights = {}; this._heights = {};
...@@ -151,12 +146,6 @@ export default class VirtualThreadList extends EventEmitter { ...@@ -151,12 +146,6 @@ export default class VirtualThreadList extends EventEmitter {
// actually be created. // actually be created.
const visibleThreads = []; const visibleThreads = [];
// List of annotations which are required to be rendered but we do not
// want them visible. This is to ensure that we allow items to be rendered
// and initialized (for saving purposes) without having them be presented
// in out of context scenarios (i.e. in wrong order for sort)
const invisibleThreads = [];
const allThreads = this._rootThread.children; const allThreads = this._rootThread.children;
const visibleHeight = this.window.innerHeight; const visibleHeight = this.window.innerHeight;
let usedHeight = 0; let usedHeight = 0;
...@@ -166,8 +155,6 @@ export default class VirtualThreadList extends EventEmitter { ...@@ -166,8 +155,6 @@ export default class VirtualThreadList extends EventEmitter {
thread = allThreads[i]; thread = allThreads[i];
const threadHeight = this._height(thread.id); const threadHeight = this._height(thread.id);
let added = false;
if ( if (
usedHeight + threadHeight < usedHeight + threadHeight <
this.scrollRoot.scrollTop - MARGIN_ABOVE this.scrollRoot.scrollTop - MARGIN_ABOVE
...@@ -180,24 +167,11 @@ export default class VirtualThreadList extends EventEmitter { ...@@ -180,24 +167,11 @@ export default class VirtualThreadList extends EventEmitter {
) { ) {
// Thread is either in or close to the viewport // Thread is either in or close to the viewport
visibleThreads.push(thread); visibleThreads.push(thread);
added = true;
} else { } else {
// Thread is below viewport // Thread is below viewport
offscreenLowerHeight += threadHeight; offscreenLowerHeight += threadHeight;
} }
// any thread that is not going to go through the render process
// because it is already outside of the viewport should be checked
// to see if it needs to be added as an invisible render. So it will
// be available to go through rendering but not visible to the user
if (
!added &&
this._options.invisibleThreadFilter &&
this._options.invisibleThreadFilter(thread)
) {
invisibleThreads.push(thread);
}
usedHeight += threadHeight; usedHeight += threadHeight;
} }
...@@ -205,13 +179,11 @@ export default class VirtualThreadList extends EventEmitter { ...@@ -205,13 +179,11 @@ export default class VirtualThreadList extends EventEmitter {
offscreenLowerHeight: offscreenLowerHeight, offscreenLowerHeight: offscreenLowerHeight,
offscreenUpperHeight: offscreenUpperHeight, offscreenUpperHeight: offscreenUpperHeight,
visibleThreads: visibleThreads, visibleThreads: visibleThreads,
invisibleThreads: invisibleThreads,
}); });
return { return {
offscreenLowerHeight, offscreenLowerHeight,
offscreenUpperHeight, offscreenUpperHeight,
visibleThreads, visibleThreads,
invisibleThreads,
}; };
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment