branch: elpa/typst-ts-mode
commit 260546ac0fc0d667dc2cb3f831dbea59740f2a36
Author: meowking <mr.meowk...@tutamail.com>
Commit: meowking <mr.meowk...@tutamail.com>

    fix: typst-ts-mode-return create new item node
---
 typst-ts-editing.el | 18 +++++++-----------
 typst-ts-mode.el    | 14 +++-----------
 2 files changed, 10 insertions(+), 22 deletions(-)

diff --git a/typst-ts-editing.el b/typst-ts-editing.el
index faa9768f00..9bef1f2044 100644
--- a/typst-ts-editing.el
+++ b/typst-ts-editing.el
@@ -124,18 +124,17 @@ When prefix ARG is non-nil, call global return function."
                               "item" t t)))
              (let* ((item-node node)
                     (has-children (treesit-node-child item-node 1))
+                    (next-line-pos
+                     (save-excursion
+                       (forward-line 1)
+                       (point)))
                     (next-line-node
                      (typst-ts-core-get-parent-of-node-at-bol-nonwhite
-                      (save-excursion
-                        (forward-line 1)
-                        (point))))
+                      next-line-pos))
                     (next-line-top-node  ; get container type or `item' type 
node
                      (typst-ts-core-parent-util-type
                       next-line-node
-                      (regexp-opt
-                       (append
-                        typst-ts-core--container-node-types
-                        '("item")))
+                      (regexp-opt '("code" "item"))
                       t)))
                (if has-children
                    ;; example:
@@ -145,10 +144,7 @@ When prefix ARG is non-nil, call global return function."
                             ;; end of buffer situation (or next line is the end
                             ;; line (and no newline character))
                             (not (equal
-                                  (line-number-at-pos
-                                   (save-excursion
-                                     (forward-line 1)
-                                     (point)))
+                                  (line-number-at-pos next-line-pos)
                                   (line-number-at-pos (point-max)))))
                        (call-interactively #'newline)
                      (typst-ts-mode-insert--item item-node))
diff --git a/typst-ts-mode.el b/typst-ts-mode.el
index 75f1a3c8fc..746b1b878f 100644
--- a/typst-ts-mode.el
+++ b/typst-ts-mode.el
@@ -438,14 +438,6 @@ NODE, PARENT and BOL see `treesit-simple-indent-rules'."
      ((and no-node (parent-is "source_file")) prev-line 0)
      ((parent-is "source_file") column-0 0)
 
-     ((n-p-gp ,(regexp-opt '(")" "]" "}" "$"))
-              ,typst-ts-mode--container-node-types-regexp
-              "item")
-      (lambda (_node parent _bol)
-        (treesit-node-start
-         (treesit-node-child (treesit-node-parent parent) 1)))
-      0)
-
      ((n-p-gp ,(regexp-opt '(")" "]" "}" "$"))
               ,typst-ts-mode--container-node-types-regexp
               nil)
@@ -467,7 +459,7 @@ NODE, PARENT and BOL see `treesit-simple-indent-rules'."
      ;; item - child item
      ((and (node-is "item") (parent-is "item")) parent-bol
       typst-ts-mode-indent-offset)
-
+     
      ;; multi-line item
      ;; -  #[hi] foo
      ;;    bar
@@ -475,7 +467,7 @@ NODE, PARENT and BOL see `treesit-simple-indent-rules'."
      ;; `adaptive-fill-regexp'
      ((match nil "item" nil 2 nil)
       typst-ts-mode--indentation-multiline-item-get-anchor 0)
-
+     
      ;; item - new item content should follow its previous line's indentation
      ;; level
      ((and no-node
@@ -486,7 +478,7 @@ NODE, PARENT and BOL see `treesit-simple-indent-rules'."
            ;;   hi #[
            ;;     - hello | <- return
            ;;   ]
-           (not (n-p-gp nil "parbreak" 
,typst-ts-mode--container-node-types-regexp)))
+           (not (n-p-gp nil "parbreak" "code")))
       typst-ts-mode--indentation-multiline-item-get-anchor_ 0)
 
      ;; raw block

Reply via email to