Skip to content

Commit 2396c25

Browse files
committed
z/leftmost tracks position correctly
1 parent b291ead commit 2396c25

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/rewrite_clj/zip/zip.clj

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,12 @@
131131
[loc]
132132
(let [{:keys [node parent left right]} loc]
133133
(if (and parent (seq left))
134-
(assoc loc
135-
:node (ffirst left)
136-
:left []
137-
:right (concat (map first (rest left)) [node] right))
134+
(let [[lnode lpos] (first left)]
135+
(assoc loc
136+
:node lnode
137+
:position lpos
138+
:left []
139+
:right (concat (map first (rest left)) [node] right)))
138140
loc)))
139141

140142
(defn insert-left

test/rewrite_clj/zip/zip_test.clj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,10 @@
5858
1 [1 7]
5959
2 [1 4]
6060
3 [1 1])
61+
62+
(fact "z/leftmost tracks position correctly"
63+
(-> (base/of-string "[hello world]")
64+
z/down
65+
z/right z/right
66+
z/leftmost
67+
z/position) => [1 2])

0 commit comments

Comments
 (0)