Skip to content

Commit 6436843

Browse files
committed
wip
1 parent 3df5e83 commit 6436843

File tree

3 files changed

+41
-24
lines changed

3 files changed

+41
-24
lines changed

src-shared/nextjournal/clojure_mode/commands.cljc

+27-23
Original file line numberDiff line numberDiff line change
@@ -139,37 +139,41 @@
139139
(defn slurp [direction]
140140
(fn [^js state]
141141
(u/update-ranges state
142-
(j/fn [^:js {:as range :keys [from to empty]}]
142+
(j/fn [^:js {:keys [from empty]}]
143143
(when empty
144144
(when-let [parent (n/closest (n/tree state from)
145-
(every-pred n/coll?
145+
(every-pred (some-fn n/coll?
146+
n/string?)
146147
#(not
147148
(case direction
148149
1 (some-> % n/with-prefix n/right n/end-edge?)
149-
-1 (some-> % n/with-prefix n/left n/start-edge?)))))]
150-
(when-let [target (case direction 1 (first (remove n/line-comment? (n/rights (n/with-prefix parent))))
151-
-1 (first (remove n/line-comment? (n/lefts (n/with-prefix parent)))))]
152-
{:cursor/mapped from
153-
:changes (case direction
154-
1
155-
(let [edge (n/down-last parent)]
156-
[{:from (-> target n/end)
157-
:insert (n/name edge)}
158-
(-> edge
159-
n/from-to
160-
(j/assoc! :insert " "))])
161-
-1
162-
(let [^string edge (n/left-edge-with-prefix state parent)
163-
start (n/start (n/with-prefix parent))]
164-
[{:from start
165-
:to (+ start (count edge))
166-
:insert " "}
167-
{:from (n/start target)
168-
:insert edge}]))})))))))
150+
-1 (some-> % n/with-prefix n/left n/start-edge?)))))]
151+
(let [str? (n/string? parent)]
152+
(when-let [target (case direction 1 (first (remove n/line-comment? (n/rights (n/with-prefix parent))))
153+
-1 (first (remove n/line-comment? (n/lefts (n/with-prefix parent)))))]
154+
(js/console.log :target target)
155+
{:cursor/mapped from
156+
:changes (case direction
157+
1
158+
(let [edge (n/down-last parent)]
159+
[{:from (-> target n/end)
160+
:insert (n/name edge)}
161+
(-> edge
162+
n/from-to
163+
(cond->
164+
(not str?) (j/assoc! :insert " ")))])
165+
-1
166+
(let [^string edge (n/left-edge-with-prefix state parent)
167+
start (n/start (n/with-prefix parent))]
168+
[{:from start
169+
:to (+ start (count edge))
170+
:insert " "}
171+
{:from (n/start target)
172+
:insert edge}]))}))))))))
169173

170174
(defn barf [direction]
171175
(fn [^js state]
172-
(->> (j/fn [^:js {:as range :keys [from to empty]}]
176+
(->> (j/fn [^:js {:keys [from empty]}]
173177
(when empty
174178
(when-let [parent (-> (n/tree state from)
175179
(n/closest n/coll?))]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(ns nextjournal.clojure-mode.scratch
2+
(:require [nextjournal.clojure-mode.commands :as commands]
3+
[nextjournal.clojure-mode :as cm-clojure]
4+
[nextjournal.clojure-mode.extensions.eval-region :as eval-region]
5+
[nextjournal.clojure-mode.test-utils :as test-utils]))
6+
7+
(def extensions
8+
(.concat cm-clojure/default-extensions (eval-region/extension #js {})))
9+
10+
(def apply-f (partial test-utils/apply-f extensions))
11+
12+
(js/console.log (apply-f (commands/slurp 1) "\"|\" 1"))

test/nextjournal/clojure_mode_tests.cljc

+2-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@
272272
"('is-d|ata) :x" 1 "('is-d|ata :x)"
273273
"('xy|z 1) 2" 1 "('xy|z 1 2)"
274274
"'ab|c 1" 1 "'ab|c 1"
275-
))
275+
276+
"\"x|\" 1" 1 "\"x1\""))
276277

277278
#?(:squint nil
278279
:cljs

0 commit comments

Comments
 (0)