From 5940d7caf21f5c2b8e322a67f32657dace56fc9a Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Fri, 5 Jun 2026 01:38:35 -0500 Subject: fix(views): make a server-side sort actually reorder the buffer A server-side sort (updated/created) refetched with the new orderBy and merged the result, but the merge updates issues in place by id and never moves them, so the buffer kept its old order and the sort had no visible effect. I caught it dogfooding live: sorting My Open Issues updated-ascending then updated-descending rendered an identical order. After the refetch I now reorder the buffer's issue subtrees to the fetched order. pearl--issue-id-ranks builds a LINEAR-ID to position map from the sorted result, and pearl--reorder-issue-subtrees takes an optional id-ranking and lays the subtrees out by it. The move is the same byte-for-byte subtree shuffle the client-side sort already uses, so unpushed edits survive. Re-checked live: updated-ascending now comes back the exact reverse of updated-descending. --- tests/test-pearl-sort.el | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests') diff --git a/tests/test-pearl-sort.el b/tests/test-pearl-sort.el index 6527989..a5292b3 100644 --- a/tests/test-pearl-sort.el +++ b/tests/test-pearl-sort.el @@ -191,6 +191,16 @@ leaving its server :sort (an IssueSortInput) untouched." (goto-char (point-min)) (should (search-forward "A stray local heading" nil t)))) +(ert-deftest test-pearl-reorder-by-id-ranks () + "With an id-rank hash, subtrees are laid out in the ranked order (server sort)." + (test-pearl-sort--in-org test-pearl-sort--flat + (let ((ranks (make-hash-table :test 'equal))) + ;; Rank i1 before i2, the reverse of the buffer's i2,i1 order. + (puthash "i1" 0 ranks) + (puthash "i2" 1 ranks) + (should (eq (pearl--reorder-issue-subtrees nil 'asc ranks) t)) + (should (equal (test-pearl-sort--issue-ids) '("i1" "i2")))))) + ;;; toggle target (ert-deftest test-pearl-toggle-target-filter-no-sort-defaults () -- cgit v1.2.3