1
0
mirror of https://codeberg.org/cage/tinmop/ synced 2025-02-02 04:36:43 +01:00

- highlighted current TOC entry while browsing gemini page/gempub;

- added hook:*before-rendering-message-visible-rows*;

- changed default: appending hooks by default in hook:add-hook.
This commit is contained in:
cage 2021-09-03 12:32:09 +02:00
parent 27d92cce37
commit c22e427f18
5 changed files with 26 additions and 1 deletions

View File

@ -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*))

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 ()