Skip to content

Commit

Permalink
Fix issue
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Dec 12, 2023
1 parent 5ce26e5 commit 5a7a6f9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 2 additions & 0 deletions public/squint/js/demo.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ let doc = `(comment
(+ 1 2 3))
` ;

// doc = `(do #_#_1 (+ 1 2 3) )`

evalCode(doc);

let state = EditorState.create( {doc: doc,
Expand Down
17 changes: 10 additions & 7 deletions src-shared/nextjournal/clojure_mode/extensions/eval_region.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
(defn uppermost-edge-here
"Returns node or its highest ancestor that starts or ends at the cursor position."
[pos node]
(or (->> (iterate n/up node)
(take-while (every-pred (complement n/top?)
#(or (= pos (n/end %) (n/end node))
(= pos (n/start %) (n/start node)))))
(last))
node))
(let [node (or (->> (iterate n/up node)
(take-while (every-pred (complement n/top?)
#(or (= pos (n/end %) (n/end node))
(= pos (n/start %) (n/start node)))))
(last))
node)]
(if (= "Discard" (n/name node))
(last (n/children node))
node)))

(defn main-selection [state]
(->
Expand All @@ -37,7 +40,7 @@
(and (not (n/terminal-type? (n/type %)))
(< (n/start %) from (n/end %))))
(-> (n/children from -1) first))))
#_(uppermost-edge-here from)
(uppermost-edge-here from)
(n/balanced-range state))))

(defn top-level-node [state]
Expand Down
4 changes: 3 additions & 1 deletion test/nextjournal/clojure_mode_tests.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,9 @@
(= (f (test-utils/make-state extensions input)) expected)
"(+ |1 2 3)" eval-region/cursor-node-string "1"
"(+ |(+ 1 2) 2 3)" eval-region/cursor-node-string "(+ 1 2)"
"(+ (+ 1 2)| 2 3)" eval-region/cursor-node-string "(+ 1 2)")
"(+ (+ 1 2)| 2 3)" eval-region/cursor-node-string "(+ 1 2)"
"(+ #_(+ 1 2)| 2 3)" eval-region/cursor-node-string "(+ 1 2)"
"(+ #_#_1 (+ 1 2)| 2 3)" eval-region/cursor-node-string "(+ 1 2)")
(let [state (test-utils/make-state extensions ";; dude\n|{:a 1}")]
(is (= "{:a 1}" (->> (eval-region/top-level-node state)
(util/range-str state)))))))
Expand Down

0 comments on commit 5a7a6f9

Please sign in to comment.