Skip to content

Commit

Permalink
mode/hint: wip.
Browse files Browse the repository at this point in the history
  • Loading branch information
aadcg committed Feb 20, 2024
1 parent 4c8d8fe commit e7afab1
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions source/mode/hint.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,24 @@ A positive value shifts to the bottom.")
(set-hint-element-style hint-element hinted-element))
hint-element)

(let ((hints-parent (ps:chain document (create-element "div")))
(hints (ps:lisp (list 'quote hints)))
(i 0))
(let* ((hints-parent (ps:chain document (create-element "div")))
(shadow (ps:chain hints-parent (attach-shadow (ps:create mode "open"))))
(hints (ps:lisp (list 'quote hints)))
(i 0))
(dolist (hinted-element (nyxt/ps:qsa document "[nyxt-hintable]"))
(let ((hint (aref hints i)))
(ps:chain hinted-element (set-attribute "nyxt-hint" hint))
(ps:chain hints-parent (append-child (create-hint-overlay hinted-element hint)))
(ps:chain shadow (append-child (create-hint-overlay hinted-element hint)))
(when (ps:lisp (show-hint-scope-p (find-submode 'hint-mode)))
(ps:chain hinted-element class-list (add "nyxt-element-hint")))
(setf i (1+ i))))
(setf (ps:@ hints-parent id) "nyxt-hints"
(ps:@ hints-parent style) "all: unset !important;")
(ps:chain document body parent-node (insert-before hints-parent
(ps:@ document body next-sibling)))
;; unless the hints root is a child of body, zooming the page breaks
;; positioning.
;; (ps:chain document body parent-node (insert-before hints-parent
;; (ps:@ document body next-sibling)))
(ps:chain document body (append-child hints-parent))
;; Don't return a value. Only the side-effects are of importance.
nil))

Expand Down Expand Up @@ -202,6 +206,8 @@ A positive value shifts to the bottom.")
(ps:chain element (remove-attribute "nyxt-hintable"))))

(defun add-hints (&key selector (buffer (current-buffer)))
;; must be added in the shadow dom
;; see https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM#applying_styles_inside_the_shadow_dom
(add-stylesheet "nyxt-hint-stylesheet"
(style (find-submode 'hint-mode))
buffer)
Expand Down

0 comments on commit e7afab1

Please sign in to comment.