From f0d19e6a5c17dbcf943f7ce27e8deba6c5185286 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Wed, 30 Oct 2013 16:49:42 +0100 Subject: [PATCH] Fix threads highlighted by the filter not being put on top. --- src/Filtering/Filter.coffee | 9 ++------- src/Miscellaneous/Index.coffee | 22 ++++++++++++++++++---- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/Filtering/Filter.coffee b/src/Filtering/Filter.coffee index 1f1387dba..eee0dfae9 100644 --- a/src/Filtering/Filter.coffee +++ b/src/Filtering/Filter.coffee @@ -110,13 +110,8 @@ Filter = # Highlight $.addClass @nodes.root, result.class - if !@isReply and result.top and g.VIEW is 'index' - # Put the highlighted OPs' thread on top of the board page... - thisThread = @nodes.root.parentNode - # ...before the first non highlighted thread. - if firstThread = $ 'div[class="postContainer opContainer"]' - unless firstThread is @nodes.root - $.before firstThread.parentNode, [thisThread, thisThread.nextElementSibling] + if !@isReply and result.top + @thread.isOnTop = true name: (post) -> if 'name' of post.info diff --git a/src/Miscellaneous/Index.coffee b/src/Miscellaneous/Index.coffee index fa717fd68..a4287e188 100644 --- a/src/Miscellaneous/Index.coffee +++ b/src/Miscellaneous/Index.coffee @@ -28,6 +28,8 @@ Index = initReady: -> $.off d, '4chanXInitFinished', Index.initReady + Index.root = $ '.board' + Index.setIndex $$ '.board > .thread, .board > hr', Index.root return if Conf['Index Mode'] is 'paged' Index.update() @@ -100,8 +102,20 @@ Index = Main.callbackNodes Thread, threads Main.callbackNodes Post, posts - board = $ '.board' - $.rmAll board - $.add board, nodes - $('.pagelist').hidden = Conf['Index Mode'] isnt 'paged' + Index.setIndex nodes $.event 'IndexRefresh' + setIndex: (nodes) -> + $.rmAll Index.root + $.add Index.root, Index.sort nodes + $('.pagelist').hidden = Conf['Index Mode'] isnt 'paged' + sort: (nodes) -> + return nodes unless Conf['Filter'] + # Put the highlighted thread on top of the index + # while keeping the original order they appear in. + tops = [] + for threadRoot in nodes by 2 when Get.threadFromRoot(threadRoot).isOnTop + tops.push threadRoot + for top, i in tops + arr = nodes.splice nodes.indexOf(top), 2 + nodes.splice i * 2, 0, arr... + nodes