Refactor Index.sort and fix hidden+highlighted threads should be at the end.

This commit is contained in:
Mayhem 2013-12-14 18:00:57 +01:00
parent cfbdf1edb5
commit 1f411efb1e

View File

@ -346,20 +346,15 @@ Index =
Index.sortedNodes.push Index.nodes[i], Index.nodes[i + 1] Index.sortedNodes.push Index.nodes[i], Index.nodes[i + 1]
if Index.isSearching if Index.isSearching
Index.sortedNodes = Index.querySearch(Index.searchInput.value) or Index.sortedNodes Index.sortedNodes = Index.querySearch(Index.searchInput.value) or Index.sortedNodes
# Move non-hidden threads on top of the index. # Sticky threads
if Conf['Anchor Hidden Threads'] Index.sortOnTop (thread) -> thread.isSticky
offset = 0 # Highlighted threads
for threadRoot, i in Index.sortedNodes by 2 when not Get.threadFromRoot(threadRoot).isHidden Index.sortOnTop((thread) -> thread.isOnTop) if Conf['Filter']
Index.sortedNodes.splice offset++ * 2, 0, Index.sortedNodes.splice(i, 2)... # Non-hidden threads
# Move sticky threads on top of the index. Index.sortOnTop((thread) -> !thread.isHidden) if Conf['Anchor Hidden Threads']
sortOnTop: (match) ->
offset = 0 offset = 0
for threadRoot, i in Index.sortedNodes by 2 when Get.threadFromRoot(threadRoot).isSticky for threadRoot, i in Index.sortedNodes by 2 when match Get.threadFromRoot threadRoot
Index.sortedNodes.splice offset++ * 2, 0, Index.sortedNodes.splice(i, 2)...
return unless Conf['Filter']
# Move highlighted threads & <hr> on top of the index
# while keeping the original order they appear in.
offset = 0
for threadRoot, i in Index.sortedNodes by 2 when Get.threadFromRoot(threadRoot).isOnTop
Index.sortedNodes.splice offset++ * 2, 0, Index.sortedNodes.splice(i, 2)... Index.sortedNodes.splice offset++ * 2, 0, Index.sortedNodes.splice(i, 2)...
return return
buildIndex: -> buildIndex: ->