Skip to content

Commit 12015ef

Browse files
committed
fix issues when pasting multiple cells with quoted text and new lines
1 parent 92fdf7d commit 12015ef

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/utils/copyPasting.test.ts

+17
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,23 @@ describe('parsePlainTextData', () => {
138138
expect(parseTextPlainData('"foo\nbar""baz"""')).toEqual([['foo\nbar"baz"']])
139139
})
140140

141+
test('single cell multi line clean', () => {
142+
expect(parseTextPlainData('"foo\nbar"')).toEqual([['foo\nbar']])
143+
})
144+
145+
test('multi cell multi line', () => {
146+
expect(parseTextPlainData('"foo\nbar"\n"baz\nqux"')).toEqual([
147+
['foo\nbar'],
148+
['baz\nqux'],
149+
])
150+
})
151+
152+
test('multi cell single line', () => {
153+
expect(parseTextPlainData('"foo\nbar"\t"baz\nqux"')).toEqual([
154+
['foo\nbar', 'baz\nqux'],
155+
])
156+
})
157+
141158
test('quoted first cell', () => {
142159
expect(parseTextPlainData('"foo\nbar')).toEqual([['"foo'], ['bar']])
143160
})

src/utils/copyPasting.ts

+4
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,13 @@ export const parseTextPlainData = (data: string): string[][] => {
3838

3939
const saveCell = () => {
4040
let str = cleanData.slice(startCell, cursor)
41+
if (str[0] === '"' && str[str.length - 1] === '"') {
42+
quoted = true
43+
}
4144

4245
if (quoted && str[str.length - 1] === '"' && str.includes('\n')) {
4346
str = str.slice(1, str.length - 1).replace(/""/g, '"')
47+
quoted = false
4448
}
4549

4650
if (quoted && str[str.length - 1] !== '"') {

0 commit comments

Comments
 (0)