Skip to content

Commit

Permalink
Preserve newlines on copy + paste (#83)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
JonShort authored Nov 29, 2020
1 parent 11b3386 commit 55c105f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
10 changes: 8 additions & 2 deletions src/components/__tests__/__snapshots__/Highlight.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ exports[`<Highlight /> snapshots renders correctly 1`] = `
<span
class="token plain"
style="display: inline-block;"
/>
>
</span>
</div>
<div
class="token-line"
Expand Down Expand Up @@ -339,7 +342,10 @@ exports[`<Highlight /> snapshots renders unsupported languages correctly 1`] = `
<span
class="token plain"
style="display: inline-block;"
/>
>
</span>
</div>
<div
class="token-line"
Expand Down
6 changes: 3 additions & 3 deletions src/utils/__tests__/normalizeTokens.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ describe("normalizeTokens", () => {
const output = normalizeTokens(input);

expect(output).toEqual([
[{ types: ["plain"], content: "", empty: true }],
[{ types: ["plain"], content: "", empty: true }],
[{ types: ["plain"], content: "", empty: true }]
[{ types: ["plain"], content: "\n", empty: true }],
[{ types: ["plain"], content: "\n", empty: true }],
[{ types: ["plain"], content: "\n", empty: true }]
]);
});
});
10 changes: 4 additions & 6 deletions src/utils/normalizeTokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@ const normalizeEmptyLines = (line: Token[]) => {
if (line.length === 0) {
line.push({
types: ["plain"],
content: "",
content: "\n",
empty: true
});
} else if (line.length === 1 && line[0].content === "") {
line[0].content = "\n";
line[0].empty = true;
}
};

const appendTypes = (
types: string[],
add: string[] | string
): string[] => {
const typesSize = types.length
const appendTypes = (types: string[], add: string[] | string): string[] => {
const typesSize = types.length;
if (typesSize > 0 && types[typesSize - 1] === add) {
return types;
}
Expand Down

0 comments on commit 55c105f

Please sign in to comment.