aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pearl.el35
-rw-r--r--tests/test-integration-acceptance.el2
-rw-r--r--tests/test-pearl-comments.el15
3 files changed, 46 insertions, 6 deletions
diff --git a/pearl.el b/pearl.el
index f988668..c549728 100644
--- a/pearl.el
+++ b/pearl.el
@@ -250,6 +250,14 @@ Returns HEADING unchanged when IDENTIFIER is empty or absent from the front."
(cond ((fboundp 'org-fold-hide-drawer-all) (org-fold-hide-drawer-all))
((fboundp 'org-cycle-hide-drawers) (org-cycle-hide-drawers 'all))))
+(defun pearl--hide-drawers-in-region (start end)
+ "Collapse property drawers between START and END.
+Used after inserting a single subtree (a freshly added comment) so its drawer
+folds shut like the rest of the page, rather than rendering expanded."
+ (save-restriction
+ (narrow-to-region start end)
+ (pearl--hide-all-drawers)))
+
(defun pearl--restore-page-visibility ()
"Re-fold the whole current buffer to its `#+STARTUP' visibility and hide drawers.
Used after a full repopulation (list / view / merge refresh) so the page does
@@ -2429,6 +2437,21 @@ GraphQL/transport failure or a non-success payload."
(and success comment (pearl--normalize-comment comment)))))
(lambda (_error _response _data) (funcall callback nil)))))
+(defun pearl--bump-comments-count-marker ()
+ "Increment the ` N/M[+]' count on the Comments heading at point, if present.
+A locally added comment grows both the shown and total counts by one. A heading
+that carries no count marker (the single-issue view) is left untouched, and the
+leading 💬 glyph is preserved either way."
+ (save-excursion
+ (let ((eol (line-end-position)))
+ (beginning-of-line)
+ (when (re-search-forward " \\([0-9]+\\)/\\([0-9]+\\)\\(\\+?\\)[ \t]*$" eol t)
+ (replace-match (format " %d/%d%s"
+ (1+ (string-to-number (match-string 1)))
+ (1+ (string-to-number (match-string 2)))
+ (match-string 3))
+ t t)))))
+
(defun pearl--append-comment-to-issue (comment)
"Insert COMMENT (a normalized plist) under the issue subtree at point.
A new comment is the newest, so it lands where `pearl-comment-sort-order' puts
@@ -2450,9 +2473,17 @@ subtree at the end of the issue when it does not exist yet."
(if (eq pearl-comment-sort-order 'newest-first)
(forward-line 1) ; just under the heading, before the first comment
(org-end-of-subtree t t)) ; after the last comment
- (insert (pearl--format-comment comment)))
+ (let ((start (point)))
+ (insert (pearl--format-comment comment))
+ (pearl--hide-drawers-in-region start (point)))
+ ;; the new comment grows the shown/total count on the heading
+ (goto-char comments-pos)
+ (pearl--bump-comments-count-marker))
+ ;; no Comments subtree yet: this is the first comment, so it is 1/1
(goto-char issue-end)
- (insert "*** Comments\n" (pearl--format-comment comment))))))
+ (let ((start (point)))
+ (insert "*** 💬 Comments 1/1\n" (pearl--format-comment comment))
+ (pearl--hide-drawers-in-region start (point)))))))
;;;###autoload
(defun pearl--create-and-append-comment (issue-id marker body)
diff --git a/tests/test-integration-acceptance.el b/tests/test-integration-acceptance.el
index 11b88b2..48dd70a 100644
--- a/tests/test-integration-acceptance.el
+++ b/tests/test-integration-acceptance.el
@@ -192,7 +192,7 @@ because the description-update mutation contains both `IssueDescription' and
(pearl-add-comment "looks good")
(should (memq 'comment-create test-integration--ops))
(goto-char (point-min))
- (should (re-search-forward "^\\*\\*\\* Comments$" nil t))
+ (should (re-search-forward "^\\*\\*\\* 💬 Comments 1/1$" nil t))
(should (re-search-forward "looks good" nil t))
;; --- edit the priority cookie, then save (reconcile-on-save) ---
(goto-char (point-min))
diff --git a/tests/test-pearl-comments.el b/tests/test-pearl-comments.el
index ae54f7d..99b705a 100644
--- a/tests/test-pearl-comments.el
+++ b/tests/test-pearl-comments.el
@@ -120,15 +120,24 @@
;;; --append-comment-to-issue
(ert-deftest test-pearl-append-comment-creates-subtree ()
- "Appending to an issue with no Comments subtree creates one."
+ "Appending to an issue with no Comments subtree creates one, glyphed and 1/1."
(test-pearl--in-org
"*** TODO [#B] Title\n:PROPERTIES:\n:LINEAR-ID: a\n:END:\nBody.\n"
(pearl--append-comment-to-issue
'(:id "c1" :author "A" :created-at "2026-05-23T09:00:00.000Z" :body "first comment"))
(goto-char (point-min))
- (should (re-search-forward "^\\*\\*\\* Comments$" nil t))
+ (should (re-search-forward "^\\*\\*\\* 💬 Comments 1/1$" nil t))
(should (re-search-forward "first comment" nil t))))
+(ert-deftest test-pearl-append-comment-bumps-count-marker ()
+ "Appending increments the shown/total count on an existing Comments heading."
+ (test-pearl--in-org
+ "** TODO [#B] Title\n:PROPERTIES:\n:LINEAR-ID: a\n:END:\nBody.\n*** 💬 Comments 1/1\n**** A — 2026-05-23T09:00:00.000Z\nfirst\n"
+ (pearl--append-comment-to-issue
+ '(:id "c2" :author "B" :created-at "2026-05-23T12:00:00.000Z" :body "second"))
+ (goto-char (point-min))
+ (should (re-search-forward "^\\*\\*\\* 💬 Comments 2/2$" nil t))))
+
(ert-deftest test-pearl-append-comment-newest-first-inserts-at-top ()
"With newest-first order, a new comment lands above the existing ones."
(let ((pearl-comment-sort-order 'newest-first))
@@ -169,7 +178,7 @@
(re-search-forward "Body.")
(pearl-add-comment "my new comment")
(goto-char (point-min))
- (should (re-search-forward "^\\*\\*\\* Comments$" nil t))
+ (should (re-search-forward "^\\*\\*\\* 💬 Comments 1/1$" nil t))
(should (re-search-forward "my new comment" nil t)))))
(ert-deftest test-pearl-add-comment-reports-failure ()