Skip to content

Commit c0c6f0d

Browse files
committed
Normalize line endings to LF during search and replace processing
- something in this block [Pasted text] breaks the processor on Windows (on macos it's fine) └── apps └── editor └── src └── utils └── changes-integration └── search-replace-processor ├── apply-search-replace-to-content │ ├── apply-search-replace-to-content.ts │ └── index.ts ├── index.ts ├── parse-search-replace-segments.ts └── types.ts
1 parent 0ac570a commit c0c6f0d

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ export const apply_search_replace_to_content = (params: {
88
original_content: string
99
segments: Segment[]
1010
}): string => {
11-
const line_ending = params.original_content.includes('\r\n') ? '\r\n' : '\n'
12-
let current_content = params.original_content
11+
const uses_crlf = params.original_content.includes('\r\n')
12+
const line_ending = '\n'
13+
let current_content = params.original_content.replace(/\r\n/g, '\n')
1314
const segments = params.segments
1415
let cursor = 0
1516

@@ -37,7 +38,7 @@ export const apply_search_replace_to_content = (params: {
3738
const clean_context_after = clean_lines(context_after)
3839

3940
// Allow invisible characters alongside tabs and spaces
40-
const SEPARATOR = '(?:[ \\t\\u200B-\\u200F\\uFEFF]*\\r?\\n){1,5}'
41+
const SEPARATOR = '(?:[ \\t\\r\\u200B-\\u200F\\uFEFF]*\\n){1,5}'
4142

4243
const build_block_pattern = (lines: string[]) => {
4344
return lines
@@ -48,7 +49,7 @@ export const apply_search_replace_to_content = (params: {
4849
const flexible = [...cleaned]
4950
.map(escape_reg_exp)
5051
.join('[\\u200B-\\u200F\\uFEFF]*')
51-
return `[ \\t\\u200B-\\u200F\\uFEFF]*${flexible}`
52+
return `[ \\t\\r\\u200B-\\u200F\\uFEFF]*${flexible}`
5253
})
5354
.join(SEPARATOR)
5455
}
@@ -122,5 +123,5 @@ export const apply_search_replace_to_content = (params: {
122123
: match_index + replacement_text.length
123124
}
124125

125-
return current_content
126+
return uses_crlf ? current_content.replace(/\n/g, '\r\n') : current_content
126127
}

0 commit comments

Comments
 (0)