Skip to content

Commit 55c105f

Browse files
authored
Preserve newlines on copy + paste (#83)
* empty line input now yields newline instead of empty string * Update unit tests to expect newline * Update snapshots to expect newline * ensure files have CRLF EoL - project convention
1 parent 11b3386 commit 55c105f

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/components/__tests__/__snapshots__/Highlight.test.js.snap

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,10 @@ exports[`<Highlight /> snapshots renders correctly 1`] = `
203203
<span
204204
class="token plain"
205205
style="display: inline-block;"
206-
/>
206+
>
207+
208+
209+
</span>
207210
</div>
208211
<div
209212
class="token-line"
@@ -339,7 +342,10 @@ exports[`<Highlight /> snapshots renders unsupported languages correctly 1`] = `
339342
<span
340343
class="token plain"
341344
style="display: inline-block;"
342-
/>
345+
>
346+
347+
348+
</span>
343349
</div>
344350
<div
345351
class="token-line"

src/utils/__tests__/normalizeTokens.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ describe("normalizeTokens", () => {
192192
const output = normalizeTokens(input);
193193

194194
expect(output).toEqual([
195-
[{ types: ["plain"], content: "", empty: true }],
196-
[{ types: ["plain"], content: "", empty: true }],
197-
[{ types: ["plain"], content: "", empty: true }]
195+
[{ types: ["plain"], content: "\n", empty: true }],
196+
[{ types: ["plain"], content: "\n", empty: true }],
197+
[{ types: ["plain"], content: "\n", empty: true }]
198198
]);
199199
});
200200
});

src/utils/normalizeTokens.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,17 @@ const normalizeEmptyLines = (line: Token[]) => {
99
if (line.length === 0) {
1010
line.push({
1111
types: ["plain"],
12-
content: "",
12+
content: "\n",
1313
empty: true
1414
});
1515
} else if (line.length === 1 && line[0].content === "") {
16+
line[0].content = "\n";
1617
line[0].empty = true;
1718
}
1819
};
1920

20-
const appendTypes = (
21-
types: string[],
22-
add: string[] | string
23-
): string[] => {
24-
const typesSize = types.length
21+
const appendTypes = (types: string[], add: string[] | string): string[] => {
22+
const typesSize = types.length;
2523
if (typesSize > 0 && types[typesSize - 1] === add) {
2624
return types;
2725
}

0 commit comments

Comments
 (0)