File tree Expand file tree Collapse file tree 3 files changed +16
-8
lines changed Expand file tree Collapse file tree 3 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,8 @@ A release with known breaking changes is marked with:
3333{issue}321[#321] ({lread}, thanks for the issue {person}openvest[@openvest]!)
3434** `join` no longer removes comments that were between joined strings
3535{issue}351[#351] ({lread})
36+ ** `split-at-pos` no longer throws on split at string opening quote
37+ {issue}350[#350] ({lread})
3638
3739=== v1.1.49 - 2024-11-18 [[v1.1.49]]
3840
Original file line number Diff line number Diff line change 446446 (update-in [0 ] #(subs % split-col))))))))
447447
448448(defn split-at-pos
449- " In string aware split
450-
451- Perform split at given position `pos` Like split, but if inside string splits string into two strings.
449+ " In-string aware split. Returns `zloc` with node found at `pos` split.
450+ If `pos` is inside a string, splits string into two strings else calls [[split]].
452451
453452 - `zloc` location is (inclusive) starting point for `pos` depth-first search
454453 - `pos` can be a `{:row :col}` map or a `[row col]` vector. The `row` and `col` values are
455454 1-based and relative to the start of the source code the zipper represents.
456455
457- Throws if `zloc` was not created with [position tracking](/doc/01-user-guide.adoc#position-tracking)."
456+ Throws if `zloc` was not created with [position tracking](/doc/01-user-guide.adoc#position-tracking).
457+
458+ - `[1 2 |3 4 5] => [1 2 |3] [4 5]`
459+ - `(\" Hello |World\" ) => (|\" Hello\" \" World\" )`"
458460 [zloc pos]
459461 (if-let [candidate (z/find-last-by-pos zloc pos)]
460- (let [pos (fz/pos-as-map pos)]
461- (if (string-node? candidate)
462+ (let [pos (fz/pos-as-map pos)
463+ candidate-pos (fz/pos-as-map (-> candidate z/position fz/pos-as-map))]
464+ (if (and (string-node? candidate) (not= pos candidate-pos))
462465 (split-string candidate pos)
463466 (split candidate)))
464467 zloc))
Original file line number Diff line number Diff line change 213213(deftest split-at-pos-test
214214 ; ; for this pos fn test, ⊚ in `s` represents character row/col the the `pos`
215215 ; ; ⊚ in `expected` is at zipper node granularity
216- (doseq [[s expected]
217- [[" (\" Hello ⊚World\" )" " (⊚\" Hello \" \" World\" )" ]]]
216+ (doseq [[s expected]
217+ [[" (\" Hello ⊚World\" 42)" " (⊚\" Hello \" \" World\" 42)" ]
218+ [" (\" ⊚Hello World\" 101)" " (⊚\"\" \" Hello World\" 101)" ]
219+ [" (\" H⊚ello World\" 101)" " (⊚\" H\" \" ello World\" 101)" ]
220+ [" (⊚\" Hello World\" 101)" " (⊚\" Hello World\" ) (101)" ]]]
218221 (let [{:keys [pos s]} (th/pos-and-s s)
219222 zloc (z/of-string* s {:track-position? true })]
220223 (doseq [pos [pos [(:row pos) (:col pos)]]]
You can’t perform that action at this time.
0 commit comments