Skip to content

Commit b2f676a

Browse files
committed
Ignore invisible formatting characters and normalize list markers in loose matching mode
- markdown lists seems to break [Pasted text] [Fragment] is not equal to [Pasted text] - remove generic-1 and create minimal test case for this [Changes] └── apps └── editor └── src └── utils └── changes-integration └── search-replace-processor └── apply-search-replace-to-content ├── apply-search-replace-to-content.spec.ts ├── apply-search-replace-to-content.ts ├── index.ts └── test-cases ├── add-blank-line │ ├── expected.txt │ ├── markers.txt │ └── original.txt ├── adjacent-blocks-and-duplicate-snippets │ ├── expected.txt │ ├── markers.txt │ └── original.txt ├── basic-conflict │ ├── expected.txt │ ├── markers.txt │ └── original.txt ├── delete-first-line │ ├── expected.txt │ ├── markers.txt │ └── original.txt ├── deletion │ ├── expected.txt │ ├── markers.txt │ └── original.txt ├── expand-line-before-blank-line │ ├── expected.txt │ ├── markers.txt │ └── original.txt ├── extra-blank-lines-in-search │ ├── expected.txt │ ├── markers.txt │ └── original.txt ├── insert-after-context │ ├── expected.txt │ ├── markers.txt │ └── original.txt ├── insert-before-context │ ├── expected.txt │ ├── markers.txt │ └── original.txt ├── invisible-chars-and-list-markers │ ├── expected.txt │ ├── markers.txt │ └── original.txt ├── multiple-conflicts │ ├── expected.txt │ ├── markers.txt │ └── original.txt ├── multiple-seven-char-equals-underlines │ ├── expected.txt │ ├── markers.txt │ └── original.txt ├── noop-blocks │ ├── expected.txt │ ├── markers.txt │ └── original.txt ├── out-of-order-blocks │ ├── expected.txt │ ├── markers.txt │ └── original.txt ├── out-of-order-shrinking-block │ ├── expected.txt │ ├── markers.txt │ └── original.txt ├── out-of-order-with-duplicate-snippet │ ├── expected.txt │ ├── markers.txt │ └── original.txt ├── prepend-empty-search │ ├── expected.txt │ ├── markers.txt │ └── original.txt ├── preserve-boundary-blank-lines │ ├── expected.txt │ ├── markers.txt │ └── original.txt ├── remove-blank-line │ ├── expected.txt │ ├── markers.txt │ └── original.txt ├── reorder-without-context │ ├── expected.txt │ ├── markers.txt │ └── original.txt ├── rst-syntax │ ├── expected.txt │ ├── markers.txt │ └── original.txt ├── seven-char-equals-underline │ ├── expected.txt │ ├── markers.txt │ └── original.txt ├── similar-code-multiple-blocks │ ├── expected.txt │ ├── markers.txt │ └── original.txt ├── strict-match-precedence │ ├── expected.txt │ ├── markers.txt │ └── original.txt ├── trailing-blank-lines-diff │ ├── expected.txt │ ├── markers.txt │ └── original.txt ├── trailing-whitespace │ ├── expected.txt │ ├── markers.txt │ └── original.txt └── whitespace-issues ├── expected.txt ├── markers.txt └── original.txt
1 parent 4db9c97 commit b2f676a

5 files changed

Lines changed: 34 additions & 3 deletions

File tree

‎apps/editor/src/utils/changes-integration/search-replace-processor/apply-search-replace-to-content/apply-search-replace-to-content.spec.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,9 @@ describe('search-replace-parser', () => {
142142
it('applies back-to-back blocks targeting identical duplicate snippets in order', () => {
143143
run_test_case('adjacent-blocks-and-duplicate-snippets')
144144
})
145+
146+
it('ignores invisible formatting characters and normalizes list markers in loose mode', () => {
147+
run_test_case('invisible-chars-and-list-markers')
148+
})
145149
})
146150
})

‎apps/editor/src/utils/changes-integration/search-replace-processor/apply-search-replace-to-content/apply-search-replace-to-content.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { Segment } from '../types'
22

3-
const INVISIBLE_CHARS_REGEX = /[\u200B-\u200F\uFEFF]/g
4-
const IGNORABLE_CHAR_REGEX = /[\s\u200B-\u200F\uFEFF]/
3+
const INVISIBLE_CHARS_REGEX =
4+
/[\u00AD\u180E\u200B-\u200F\u202A-\u202E\u2060\u2066-\u2069\uFEFF]/g
5+
const IGNORABLE_CHAR_REGEX =
6+
/[\s\u00AD\u180E\u200B-\u200F\u202A-\u202E\u2060\u2066-\u2069\uFEFF]/
57
const EQUALS_DIVIDER_REGEX = /^={7}$/
68
const MAX_CONTEXT_LINES = 5
79

@@ -25,7 +27,11 @@ const strip_invisible = (text: string): string =>
2527
const normalize_strict: Normalizer = (line) => strip_invisible(line).trim()
2628

2729
const normalize_loose: Normalizer = (line) =>
28-
strip_invisible(line).replace(/\s+/g, ' ').trim()
30+
strip_invisible(line)
31+
.replace(/\s+/g, ' ')
32+
.trim()
33+
.replace(/^[-*+]\s+/, '- ')
34+
.replace(/^\d+[.)]\s+/, '1. ')
2935

3036
const index_non_blank_lines = (params: {
3137
content: string
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- first item updated
2+
- second item updated
3+
1. third item updated
4+
2. fourth item updated
5+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<<<<<<< SEARCH
2+
* first item
3+
​- second item
4+
1) third item
5+
2. fourth item
6+
=======
7+
- first item updated
8+
- second item updated
9+
1. third item updated
10+
2. fourth item updated
11+
>>>>>>> REPLACE
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
­- first item
2+
+ second⁠ item
3+
1. third⁦ item
4+
2) fourth‪ item
5+

0 commit comments

Comments
 (0)