diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-26 19:28:05 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-26 19:28:05 -0500 |
| commit | 00571a577e12e4a59b1400e9712e3423e4730643 (patch) | |
| tree | 560f174d85367077f02cdd57d4f2e9cb448b85ed /pearl.el | |
| parent | 899c55f230d96649bdd3a3f4a8a0302ecf2df994 (diff) | |
| download | pearl-00571a577e12e4a59b1400e9712e3423e4730643.tar.gz pearl-00571a577e12e4a59b1400e9712e3423e4730643.zip | |
feat(comments): fold the drawer and update the heading count on add
Adding a comment left three rough edges. Its property drawer rendered expanded while every other drawer in the page was folded, so I fold the new subtree's drawers right after inserting it. The Comments heading's count went stale on add: a freshly created subtree now shows 💬 Comments 1/1, and an existing 💬 Comments N/M bumps to N+1/M+1. And the fallback that creates the Comments subtree when an issue had none was still inserting a glyph-less "Comments". It now leads with the 💬 like the rest.
Diffstat (limited to 'pearl.el')
| -rw-r--r-- | pearl.el | 35 |
1 files changed, 33 insertions, 2 deletions
@@ -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) |
