Skip to content

Commit e114063

Browse files
committed
z/insert-left fixes the position
1 parent ff195b9 commit e114063

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/rewrite_clj/zip/zip.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@
148148
(throw (new Exception "Insert at top"))
149149
(assoc loc
150150
:changed? true
151-
:left (conj left [item position])))))
151+
:left (conj left [item position])
152+
:position (node/+extent position (node/extent item))))))
152153

153154
(defn insert-right
154155
"Inserts the item as the right sibling of the node at this loc,

test/rewrite_clj/zip/zip_test.clj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,10 @@
8282
z/down
8383
(z/insert-right 'x)
8484
z/position) => [1 2])
85+
86+
(fact "z/insert-left fixes the position"
87+
(-> (base/of-string "[hello world]")
88+
z/down
89+
z/right
90+
(z/insert-left 'x)
91+
z/position) => [1 8])

0 commit comments

Comments
 (0)