diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-05 01:38:35 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-05 01:38:35 -0500 |
| commit | 5940d7caf21f5c2b8e322a67f32657dace56fc9a (patch) | |
| tree | d5eb951bed71e2e25c7e45bd14e0fa5605e1c7ff /tests/test-pearl-sort.el | |
| parent | 3f491e73cdbdc03d652bce81fdfc68eabb313213 (diff) | |
| download | pearl-5940d7caf21f5c2b8e322a67f32657dace56fc9a.tar.gz pearl-5940d7caf21f5c2b8e322a67f32657dace56fc9a.zip | |
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.
Diffstat (limited to 'tests/test-pearl-sort.el')
| -rw-r--r-- | tests/test-pearl-sort.el | 10 |
1 files changed, 10 insertions, 0 deletions
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 () |
