diff --git a/src-shared/nextjournal/clojure_mode/commands.cljc b/src-shared/nextjournal/clojure_mode/commands.cljc index 3a67d09..7fd2f5d 100644 --- a/src-shared/nextjournal/clojure_mode/commands.cljc +++ b/src-shared/nextjournal/clojure_mode/commands.cljc @@ -139,37 +139,41 @@ (defn slurp [direction] (fn [^js state] (u/update-ranges state - (j/fn [^:js {:as range :keys [from to empty]}] + (j/fn [^:js {:keys [from empty]}] (when empty (when-let [parent (n/closest (n/tree state from) - (every-pred n/coll? + (every-pred (some-fn n/coll? + n/string?) #(not (case direction 1 (some-> % n/with-prefix n/right n/end-edge?) - -1 (some-> % n/with-prefix n/left n/start-edge?)))))] - (when-let [target (case direction 1 (first (remove n/line-comment? (n/rights (n/with-prefix parent)))) - -1 (first (remove n/line-comment? (n/lefts (n/with-prefix parent)))))] - {:cursor/mapped from - :changes (case direction - 1 - (let [edge (n/down-last parent)] - [{:from (-> target n/end) - :insert (n/name edge)} - (-> edge - n/from-to - (j/assoc! :insert " "))]) - -1 - (let [^string edge (n/left-edge-with-prefix state parent) - start (n/start (n/with-prefix parent))] - [{:from start - :to (+ start (count edge)) - :insert " "} - {:from (n/start target) - :insert edge}]))}))))))) + -1 (some-> % n/with-prefix n/left n/start-edge?)))))] + (let [str? (n/string? parent)] + (when-let [target (case direction 1 (first (remove n/line-comment? (n/rights (n/with-prefix parent)))) + -1 (first (remove n/line-comment? (n/lefts (n/with-prefix parent)))))] + (js/console.log :target target) + {:cursor/mapped from + :changes (case direction + 1 + (let [edge (n/down-last parent)] + [{:from (-> target n/end) + :insert (n/name edge)} + (-> edge + n/from-to + (cond-> + (not str?) (j/assoc! :insert " ")))]) + -1 + (let [^string edge (n/left-edge-with-prefix state parent) + start (n/start (n/with-prefix parent))] + [{:from start + :to (+ start (count edge)) + :insert " "} + {:from (n/start target) + :insert edge}]))})))))))) (defn barf [direction] (fn [^js state] - (->> (j/fn [^:js {:as range :keys [from to empty]}] + (->> (j/fn [^:js {:keys [from empty]}] (when empty (when-let [parent (-> (n/tree state from) (n/closest n/coll?))] diff --git a/src-shared/nextjournal/clojure_mode/scratch.cljs b/src-shared/nextjournal/clojure_mode/scratch.cljs new file mode 100644 index 0000000..7e48c2c --- /dev/null +++ b/src-shared/nextjournal/clojure_mode/scratch.cljs @@ -0,0 +1,12 @@ +(ns nextjournal.clojure-mode.scratch + (:require [nextjournal.clojure-mode.commands :as commands] + [nextjournal.clojure-mode :as cm-clojure] + [nextjournal.clojure-mode.extensions.eval-region :as eval-region] + [nextjournal.clojure-mode.test-utils :as test-utils])) + +(def extensions + (.concat cm-clojure/default-extensions (eval-region/extension #js {}))) + +(def apply-f (partial test-utils/apply-f extensions)) + +(js/console.log (apply-f (commands/slurp 1) "\"|\" 1")) diff --git a/test/nextjournal/clojure_mode_tests.cljc b/test/nextjournal/clojure_mode_tests.cljc index aade04c..ac732fe 100644 --- a/test/nextjournal/clojure_mode_tests.cljc +++ b/test/nextjournal/clojure_mode_tests.cljc @@ -272,7 +272,8 @@ "('is-d|ata) :x" 1 "('is-d|ata :x)" "('xy|z 1) 2" 1 "('xy|z 1 2)" "'ab|c 1" 1 "'ab|c 1" - )) + + "\"x|\" 1" 1 "\"x1\"")) #?(:squint nil :cljs