Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve newlines on copy + paste #83

Merged
merged 4 commits into from Nov 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/components/__tests__/__snapshots__/Highlight.test.js.snap
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
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
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