Skip to content

Commit

Permalink
Added support for Option+Enter in code blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
svetlyak40wt committed Mar 27, 2022
1 parent 7a94dee commit 61c1c41
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/editor.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
(:import-from #:metacopy
#:copy-thing)
(:import-from #:reblocks-text-editor/utils/text
#:+zero-width-space+
#:trim-spaces
#:remove-html-tags)
(:import-from #:reblocks-text-editor/blocks/code
Expand Down Expand Up @@ -270,6 +271,29 @@ Second line
0
:from-the-end t))))))

(defgeneric start-new-paragraph (document path-or-node)
(:documentation "Creates a new paragraph right after the current node and moves caret into it.")
(:method ((document t) (path-or-node t))))


(defmethod start-new-paragraph (document (path list))
(log:debug "Creating a new paragraph after the node at" path)

(let* ((node
(reblocks-text-editor/document/ops::find-changed-node document path)))
(start-new-paragraph document node)))


(defmethod start-new-paragraph (document (node common-doc:document-node))
(let ((paragraph (common-doc:make-paragraph
(common-doc:make-text +zero-width-space+))))
(ops::add-reference-ids document :to-node paragraph)
(ops::insert-node document paragraph
:relative-to node)
(ops::ensure-cursor-position-is-correct document
(first (common-doc:children paragraph))
0)))


(defgeneric on-document-update (widget)
(:documentation "Called after the each document update.")
Expand Down Expand Up @@ -392,6 +416,9 @@ Second line
((string= change-type
"maybe-delete-block")
(maybe-delete-block document path))
((string= change-type
"start-new-paragraph")
(start-new-paragraph document path))
(t
(process-usual-update document path new-html cursor-position)))

Expand Down
9 changes: 9 additions & 0 deletions src/frontend/js.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,15 @@

(defun make-code-block-keymap ()
(list
(create :name "Option+Enter"
:predicate
(lambda (event)
(and (= (@ event key)
"Enter")
(@ event alt-key)))
:func
(lambda (event)
(change-text event "start-new-paragraph")))
(create :name "Enter"
:predicate
(lambda (event)
Expand Down

0 comments on commit 61c1c41

Please sign in to comment.