|
112 | 112 | (defn nav [dir] |
113 | 113 | (fn [state] |
114 | 114 | (u/update-ranges state |
115 | | - (j/fn [^:js {:as range :keys [from to empty]}] |
| 115 | + (j/fn [^:js {:keys [from to empty]}] |
116 | 116 | (if empty |
117 | 117 | {:cursor (nav-position state from dir)} |
118 | 118 | {:cursor (j/get (u/from-to from to) (case dir -1 :from 1 :to))}))))) |
119 | 119 |
|
120 | 120 | (defn nav-select [dir] |
121 | 121 | (fn [^js state] |
122 | 122 | (u/update-ranges state |
123 | | - (j/fn [^:js {:as range :keys [from to empty]}] |
| 123 | + (j/fn [^:js {:keys [from to empty]}] |
124 | 124 | (if empty |
125 | 125 | {:range (n/balanced-range state from (nav-position state from dir))} |
126 | 126 | {:range (j/let [^:js {:keys [from to]} (u/from-to from to)] |
|
136 | 136 |
|
137 | 137 | (def log js/console.log) |
138 | 138 |
|
| 139 | +(defn ->str [x] |
| 140 | + (js/JSON.stringify (str x))) |
| 141 | + |
139 | 142 | (defn slurp [direction] |
140 | 143 | (fn [^js state] |
141 | 144 | (u/update-ranges state |
142 | | - (j/fn [^:js {:as range :keys [from to empty]}] |
| 145 | + (j/fn [^:js {:keys [from empty]}] |
143 | 146 | (when empty |
144 | 147 | (when-let [parent (n/closest (n/tree state from) |
145 | | - (every-pred n/coll? |
| 148 | + (every-pred (some-fn n/coll? |
| 149 | + n/string?) |
146 | 150 | #(not |
147 | 151 | (case direction |
148 | 152 | 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}]))}))))))) |
| 153 | + -1 (some-> % n/with-prefix n/left n/start-edge?)))))] |
| 154 | + (let [str? (n/string? parent)] |
| 155 | + (when-let [target (case direction 1 (first (remove n/line-comment? (n/rights (n/with-prefix parent)))) |
| 156 | + -1 (first (remove n/line-comment? (n/lefts (n/with-prefix parent)))))] |
| 157 | + {:cursor/mapped from |
| 158 | + :changes (case direction |
| 159 | + 1 |
| 160 | + (let [edge (n/down-last parent)] |
| 161 | + #js [#js {:from (-> target n/end) |
| 162 | + :insert (n/name edge)} |
| 163 | + (-> edge |
| 164 | + n/from-to |
| 165 | + (cond-> |
| 166 | + (not str?) (j/assoc! :insert " ")))]) |
| 167 | + -1 |
| 168 | + (let [^string edge (n/left-edge-with-prefix state parent) |
| 169 | + start (n/start (n/with-prefix parent))] |
| 170 | + #js [(cond-> #js {:from start |
| 171 | + :to (+ start (count edge))} |
| 172 | + (not str?) (j/assoc! :insert " ")) |
| 173 | + #js {:from (n/start target) |
| 174 | + :insert edge}]))})))))))) |
169 | 175 |
|
170 | 176 | (defn barf [direction] |
171 | 177 | (fn [^js state] |
172 | | - (->> (j/fn [^:js {:as range :keys [from to empty]}] |
| 178 | + (->> (j/fn [^:js {:keys [from empty]}] |
173 | 179 | (when empty |
174 | 180 | (when-let [parent (-> (n/tree state from) |
175 | 181 | (n/closest n/coll?))] |
|
0 commit comments