Skip to content

Commit

Permalink
Show active code-block.
Browse files Browse the repository at this point in the history
  • Loading branch information
svetlyak40wt committed Mar 26, 2022
1 parent 0640166 commit 7cf49f9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
13 changes: 9 additions & 4 deletions src/frontend/css.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@
:padding 0)
(.code-block
:background-color "#EEE"
:box-sizing border-box
;; Invisible border (will become visible for active block)
:border 1px solid "#EEE"

:margin-left -0.5rem
:padding-left 0.5rem
:margin-right -0.5rem
:padding-right 0.5rem
:min-width 10rem
:min-height 2rem
;; ((:and code :after)
;; :content " ")
)
:min-height 2rem)
((:and .code-block .active)
:border 1px solid "#444"
(code
:border none))
((:and p .active)
(.markup :display inline-block))))))
20 changes: 10 additions & 10 deletions src/frontend/js.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
(t
(chain console (log "Unable to find element to place cursor to" element-id))))

(update-active-paragraph)))
(update-active-block)))

(defun take (n arr)
(loop for item in arr
Expand Down Expand Up @@ -371,23 +371,23 @@

(defvar +prev-current-node+ nil)

(defun update-active-paragraph ()
(defun update-active-block ()
(let* ((selection (chain window
(get-selection)))
(node (@ selection
base-node)))
(unless (eql +prev-current-node+
node)
(let* ((current-paragraph (go-up-to "P" node))
(editor (get-editor-content-node current-paragraph)))
(let* ((current-block (go-up-to-block-node node))
(editor (get-editor-content-node current-block)))
(when editor
(let ((all-paragraphs (chain editor
(get-elements-by-tag-name "P"))))
(loop for p in all-paragraphs
(let ((all-blocks (chain editor
(query-selector-all ".block"))))
(loop for p in all-blocks
do (chain p
class-list
(remove "active")))
(chain current-paragraph
(chain current-block
class-list
(add "active"))))))))

Expand Down Expand Up @@ -449,7 +449,7 @@
(open-link event link-href))
(t
(show-path)
(update-active-paragraph)))))
(update-active-block)))))

(defun make-defaut-keymap ()
(list
Expand Down Expand Up @@ -626,7 +626,7 @@
(chain event
(prevent-default))))
(unless handler-called
(update-active-paragraph))))
(update-active-block))))

(defun on-paste (event)
(chain console
Expand Down

0 comments on commit 7cf49f9

Please sign in to comment.