File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change 4
4
; ; ## Remove
5
5
6
6
(defn- update-in-path
7
- [{ :keys [node path] :as loc} k f]
7
+ [loc k f]
8
8
(if-let [v (get loc k)]
9
9
(assoc loc :changed? true k (f v))
10
10
loc))
16
16
17
17
(defn remove-left
18
18
" Remove left sibling of the current node (if there is one)."
19
- [loc]
20
- (update-in-path loc :left pop))
19
+ [{:keys [left] :as loc}]
20
+ (if-let [[_ lpos] (peek left)]
21
+ (assoc loc
22
+ :left (pop left)
23
+ :position lpos
24
+ :changed? true )
25
+ loc))
21
26
22
27
(defn remove-right-while
23
28
" Remove elements to the right of the current zipper location as long as
Original file line number Diff line number Diff line change 46
46
3 [1 4 ]
47
47
1 [1 2 ]
48
48
2 [1 3 ])
49
+
50
+ (tabular
51
+ (fact " `remove-left` tracks current position correctly"
52
+ (let [root (base/of-string " [a bb ccc]" )
53
+ zloc (nth (iterate z/next root) ?n)]
54
+ (z/position (remove-left zloc)) => ?pos))
55
+ ?n ?pos
56
+ 3 [1 3 ]
57
+ 5 [1 6 ])
You can’t perform that action at this time.
0 commit comments