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:
33
33
{issue}321[#321] ({lread}, thanks for the issue {person}openvest[@openvest]!)
34
34
** `join` no longer removes comments that were between joined strings
35
35
{issue}351[#351] ({lread})
36
+ ** `split-at-pos` no longer throws on split at string opening quote
37
+ {issue}350[#350] ({lread})
36
38
37
39
=== v1.1.49 - 2024-11-18 [[v1.1.49]]
38
40
Original file line number Diff line number Diff line change 446
446
(update-in [0 ] #(subs % split-col))))))))
447
447
448
448
(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]].
452
451
453
452
- `zloc` location is (inclusive) starting point for `pos` depth-first search
454
453
- `pos` can be a `{:row :col}` map or a `[row col]` vector. The `row` and `col` values are
455
454
1-based and relative to the start of the source code the zipper represents.
456
455
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\" )`"
458
460
[zloc pos]
459
461
(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))
462
465
(split-string candidate pos)
463
466
(split candidate)))
464
467
zloc))
Original file line number Diff line number Diff line change 213
213
(deftest split-at-pos-test
214
214
; ; for this pos fn test, ⊚ in `s` represents character row/col the the `pos`
215
215
; ; ⊚ 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)" ]]]
218
221
(let [{:keys [pos s]} (th/pos-and-s s)
219
222
zloc (z/of-string* s {:track-position? true })]
220
223
(doseq [pos [pos [(:row pos) (:col pos)]]]
You can’t perform that action at this time.
0 commit comments