Skip to content

Commit 7455275

Browse files
authored
Merge pull request #273 from tamagokun/mk-paste-fix
fix issues when pasting multiple cells with quoted text and new lines
2 parents f227436 + 12015ef commit 7455275

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
@@ -139,6 +139,23 @@ describe('parsePlainTextData', () => {
139139
expect(parseTextPlainData('"foo\nbar""baz"""')).toEqual([['foo\nbar"baz"']])
140140
})
141141

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

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)