diff --git a/src/gemini-page-toc.lisp b/src/gemini-page-toc.lisp index c5fe27d..4e964e9 100644 --- a/src/gemini-page-toc.lisp +++ b/src/gemini-page-toc.lisp @@ -83,6 +83,18 @@ (win-clear object) (draw object)))))) +(defun highlight-current-section (visible-rows window) + (declare (ignore window)) + (when-let* ((toc-win *gemini-toc-window*) + (line-fields (fields (first visible-rows))) + (gid (getf line-fields :group-id)) + (index (position-if (lambda (a) (= (getf (fields a) :group-id) + gid)) + (rows toc-win)))) + (unselect-all toc-win) + (select-row toc-win index) + (draw toc-win))) + (defun open-toc-window (gemini-window) (let* ((low-level-window (make-croatoan-window :enable-function-keys t))) (setf *gemini-toc-window* @@ -96,5 +108,7 @@ (resync-rows-db *gemini-toc-window* :redraw nil) (when (not (line-oriented-window:rows-empty-p *gemini-toc-window*)) (select-row *gemini-toc-window* 0)) + (hooks:add-hook 'hooks:*before-rendering-message-visible-rows* + #'highlight-current-section) (draw *gemini-toc-window*) *gemini-toc-window*)) diff --git a/src/hooks.lisp b/src/hooks.lisp index 9102ac8..0f1f0e6 100644 --- a/src/hooks.lisp +++ b/src/hooks.lisp @@ -21,7 +21,7 @@ (defgeneric add-hook (hook fn &key append) (:documentation "Add FN to the value of HOOK.") - (:method ((hook symbol) fn &key append) + (:method ((hook symbol) fn &key (append t)) (declare (type (or function symbol) fn)) (if (not append) (pushnew fn (symbol-value hook)) @@ -88,6 +88,11 @@ non-nil.") "Run this hooks before rendering the message on a message-window (the message window is passed as parameter") +(defparameter *before-rendering-message-visible-rows* '() + "Run this hooks before rendering the visible portion of rows of a + message on a message-window (parameters the visible rows and the + message window") + (defparameter *before-sending-message* '() "Run this hooks before sending the message, note that the message could be encrypted after this hooks runs, the function takes a diff --git a/src/message-window.lisp b/src/message-window.lisp index 1c3af12..b617614 100644 --- a/src/message-window.lisp +++ b/src/message-window.lisp @@ -139,6 +139,8 @@ (let ((visible-rows (visible-rows window)) (window-width (win-width-no-border window)) (content-available-on-the-left-mark (swconf:left-arrow))) + (when hooks:*before-rendering-message-visible-rows* + (hooks:run-hook 'hooks:*before-rendering-message-visible-rows* visible-rows window)) (loop for line in visible-rows for y from 1 do diff --git a/src/package.lisp b/src/package.lisp index 54b713a..4a89f83 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -1611,6 +1611,7 @@ :*before-main-loop* :*before-quit* :*before-rendering-message-text* + :*before-rendering-message-visible-rows* :*before-sending-message* :*skip-message-hook* :*after-saving-message* @@ -2217,6 +2218,7 @@ (:shadowing-import-from :text-utils :split-lines) (:shadowing-import-from :misc :random-elt :shuffle) (:export + :highlight-current-section :open-toc-window)) (defpackage :command-window diff --git a/src/ui-goodies.lisp b/src/ui-goodies.lisp index 53809d3..4e4a5f0 100644 --- a/src/ui-goodies.lisp +++ b/src/ui-goodies.lisp @@ -2066,6 +2066,8 @@ gemini page the program is rendering." (gemini-toc-jump-to-entry)) (defun gemini-toc-close () + (hooks:remove-hook 'hooks:*before-rendering-message-visible-rows* + #'gemini-page-toc:highlight-current-section) (close-window-and-return-to-message *gemini-toc-window*)) (defun gemini-toc-scroll-down-page ()