fix: turn bare carriage returns into spaces in excel cells

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
wuzilongandCursor committed 2026-10-19 19:13:52 +08:00
1 parent aae4465f6c
commit e1e6c55316
2 files changed
+14 -5

No files matched your search

+10 -3
View File
@@ -29,6 +29,7 @@ describe('excelCell', () => {
it('trims and turns tabs and line breaks into spaces', () => {
assert.equal(excelCell(' 合作中 \n'), '合作中')
assert.equal(excelCell('重庆\t长寿\r\n区'), '重庆 长寿 区')
assert.equal(excelCell('重庆\r长寿'), '重庆 长寿')
})
})
@@ -53,7 +54,10 @@ describe('toggleAxis', () => {
it('shift-selects inclusive span and keeps earlier picks: start with set containing 0 and anchor 0, shift-click 3 yields 0,1,2,3 and anchor 3', () => {
const selected = new Set([0])
const result = toggleAxis(selected, 3, true, 0)
assert.deepEqual([...result.selected].sort((a, b) => a - b), [0, 1, 2, 3])
assert.deepEqual(
[...result.selected].sort((a, b) => a - b),
[0, 1, 2, 3]
)
assert.equal(result.anchor, 3)
})
@@ -111,10 +115,13 @@ describe('resolveCopyAxes', () => {
describe('buildExcelTsv', () => {
it('builds CRLF-separated TSV with header row', () => {
const tsv = buildExcelTsv(['联系人', '状态'], [
const tsv = buildExcelTsv(
['联系人', '状态'],
[
['张三', '合作中'],
['李四', '跟进中']
])
]
)
assert.equal(tsv, '联系人\t状态\r\n张三\t合作中\r\n李四\t跟进中')
})
})
+4 -2
View File
@@ -16,7 +16,7 @@ export function isCopyableColumn(col: ListExcelColumn): boolean {
export function excelCell(value: string): string {
return String(value ?? '')
.replace(/\t/g, ' ')
.replace(/\r?\n/g, ' ')
.replace(/\r\n|\r|\n/g, ' ')
.trim()
}
@@ -46,7 +46,9 @@ export function resolveCopyAxes(input: {
}): { cols: number[]; rows: number[] } | null {
const { selectedCols, selectedRows, columnCount, rowCount } = input
if (!selectedCols.length && !selectedRows.length) return null
const cols = (selectedCols.length ? selectedCols : range(columnCount)).slice().sort((a, b) => a - b)
const cols = (selectedCols.length ? selectedCols : range(columnCount))
.slice()
.sort((a, b) => a - b)
const rows = (selectedRows.length ? selectedRows : range(rowCount)).slice().sort((a, b) => a - b)
return { cols, rows }
}