Skip to content

Commit 3d11056

Browse files
Merge pull request #63 from Akhand-99/issue/windows-line-endings
adding logic to handle windows line endings when content is pasted on…
2 parents 591b2b5 + 19b7155 commit 3d11056

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

component/src/utils/paste/CSV/parseCSVClipboardText.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export class ParseCSVClipboardText {
66
public static readonly NEW_LINE_SYMBOL = '\\n';
77
private static readonly EXPLICIT_TAB_SYMBOL = '\\\\t';
88
private static readonly EXPLICIT_NEW_LINE_SYMBOL = '\\\\n';
9+
private static readonly WINDOWS_NEW_LINE_SYMBOL = '\\r\\n';
10+
private static readonly EXPLICIT_WINDOWS_NEW_LINE_SYMBOL = '\\\\r\\\\n';
911

1012
private static preprocessText(multiLineString: string): string {
1113
let newString = multiLineString;
@@ -20,6 +22,17 @@ export class ParseCSVClipboardText {
2022

2123
private static getSeparatorSymbols(multiLineString: string): {newLine: string; tab: string} {
2224
// occurs when pasting string that contains actual \n or \t symbols
25+
26+
// Handle Windows-style line endings (`\r\n`)
27+
if (multiLineString.indexOf(ParseCSVClipboardText.EXPLICIT_WINDOWS_NEW_LINE_SYMBOL) > -1) {
28+
return {
29+
newLine: ParseCSVClipboardText.EXPLICIT_WINDOWS_NEW_LINE_SYMBOL, tab: ParseCSVClipboardText.EXPLICIT_TAB_SYMBOL
30+
};
31+
}
32+
if (multiLineString.indexOf(ParseCSVClipboardText.WINDOWS_NEW_LINE_SYMBOL) > -1) {
33+
return { newLine: ParseCSVClipboardText.WINDOWS_NEW_LINE_SYMBOL, tab: ParseCSVClipboardText.TAB_SYMBOL };
34+
}
35+
// Handle Unix-style line endings (`\n`)
2336
if (
2437
multiLineString.indexOf(ParseCSVClipboardText.EXPLICIT_NEW_LINE_SYMBOL) > -1 ||
2538
multiLineString.indexOf(ParseCSVClipboardText.EXPLICIT_TAB_SYMBOL) > -1

0 commit comments

Comments
 (0)