Skip to content

Commit

Permalink
perf: Wait for post command to render
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Jul 1, 2024
1 parent 5b8abb6 commit fe9134e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,6 @@ turn off `ts-fold-mode`
(lambda (&rest _)
(null (ts-fold--overlays-in 'ts-fold-indicators-window (selected-window)
(line-beginning-position) (line-end-position)))))
(advice-add 'line-reminder-transfer-to-saved-lines :after
;; Refresh indicators for package `ts-fold'.
#'ts-fold-indicators-refresh)
```
### 📝 Summary
Expand Down
31 changes: 22 additions & 9 deletions ts-fold-indicators.el
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,19 @@
"Enable `ts-fold-indicators' mode."
(if (or ts-fold-mode (ts-fold-mode 1)) ; Enable `ts-fold-mode' automatically
(progn
(add-hook 'tree-sitter-after-change-functions #'ts-fold-indicators-refresh nil t)
(add-hook 'after-save-hook #'ts-fold-indicators-refresh nil t)
(add-hook 'tree-sitter-after-change-functions #'ts-fold-indicators--trigger-render nil t)
(add-hook 'post-command-hook #'ts-fold-indicators--post-command nil t)
(add-hook 'after-save-hook #'ts-fold-indicators--trigger-render nil t)
(add-hook 'window-size-change-functions #'ts-fold-indicators--size-change)
(add-hook 'window-scroll-functions #'ts-fold-indicators--scroll)
(ts-fold-indicators--render-buffer))
(ts-fold-indicators-mode -1)))

(defun ts-fold-indicators--disable ()
"Disable `ts-fold-indicators' mode."
(remove-hook 'tree-sitter-after-change-functions #'ts-fold-indicators-refresh t)
(remove-hook 'after-save-hook #'ts-fold-indicators-refresh t)
(remove-hook 'tree-sitter-after-change-functions #'ts-fold-indicators--trigger-render t)
(remove-hook 'post-command-hook #'ts-fold-indicators--post-command t)
(remove-hook 'after-save-hook #'ts-fold-indicators--trigger-render t)
(remove-hook 'window-size-change-functions #'ts-fold-indicators--size-change)
(remove-hook 'window-scroll-functions #'ts-fold-indicators--scroll)
(ts-fold-indicators--remove-ovs-buffer))
Expand Down Expand Up @@ -291,6 +293,9 @@ Argument FOLDED holds folding state; it's a boolean."
;; (@* "Update" )
;;

(defvar-local ts-fold-indicators--render-this-command-p nil
"Set to non-nil if render current command.")

(defun ts-fold-indicators--create (node)
"Create indicators using NODE."
(when-let* ((range (ts-fold--get-fold-range node))
Expand Down Expand Up @@ -318,14 +323,22 @@ Argument FOLDED holds folding state; it's a boolean."
(ts-fold--with-selected-window window
(ignore-errors (ts-fold-indicators-refresh))))

(defun ts-fold-indicators--within-window (node &optional wend wstart)
(defun ts-fold-indicators--trigger-render (&rest _)
"Trigger rendering on the next redisplay."
(setq ts-fold-indicators--render-this-command-p t)) ; Trigger render at the end.

(defun ts-fold-indicators--post-command ()
"Post command."
(when ts-fold-indicators--render-this-command-p
(ts-fold-indicators-refresh)
(setq ts-fold-indicators--render-this-command-p nil)))

(defun ts-fold-indicators--within-window (node wend wstart)
"Return nil if NODE is not within the current window display range.
Optional arguments WEND and WSTART are the range for caching."
Arguments WEND and WSTART are the range for caching."
(when-let*
((wend (or wend (window-end nil t)))
(wstart (or wstart (window-start)))
(range (cl-case ts-fold-indicators-render-method
((range (cl-case ts-fold-indicators-render-method
(`full
(ignore-errors (ts-fold--get-fold-range node)))
(`partial (cons (tsc-node-start-position node)
Expand Down

0 comments on commit fe9134e

Please sign in to comment.