Note: this issue was drafted with the help of Claude (Claude Code). The root-cause analysis and the suggested fix were verified against the current source and against live behaviour in 6.3.1.
Description
The built-in table clipboard paste parser splits pasted data on \n only and does not handle \r\n line endings. When pasting data copied from Excel (and most Windows apps), which ends rows with \r\n and adds a trailing \r\n after the last row, two problems occur:
- The
\r from each \r\n stays attached to the value of the last column of every row (e.g. a pasted y1 becomes "y1\r").
- The trailing
\r\n produces an extra empty trailing row, which — depending on clipboardPasteAction — either inserts a blank row or overwrites the cell below the target with an empty value.
This is the same underlying problem reported long ago in #2489, which was closed without a fix (no reproducible example was provided at the time). It still reproduces on 6.3.1 / current master.
Steps to reproduce
- A table with
clipboard: true.
- Copy a 2×2 range from Excel — clipboard content is
x1\ty1\r\nx2\ty2\r\n.
- Paste into the table.
Expected
[["x1","y1"],["x2","y2"]] — clean values, no stray \r, no extra empty row.
Actual
Parser produces [["x1","y1\r"],["x2","y2\r"],[""]] — \r stuck on the last column of each row, plus a trailing empty row.
Root cause
src/js/modules/Clipboard/defaults/pasteParsers.js, the table parser:
clipboard = clipboard.split("\n"); // only \n; \r\n and trailing newline not handled
clipboard.forEach(function(row){
data.push(row.split("\t"));
});
Suggested fix
Normalize line endings and drop a single trailing blank line before splitting:
clipboard = clipboard.replace(/\r\n?/g, "\n").replace(/\n$/, "");
For reference, ag-Grid handles this in its clipboard parser by treating \r\n as a single line break (skipping the \n after a \r) and removing a trailing blank line (suppressLastEmptyLineOnPaste → removeLastLineIfBlank).
Environment
- Tabulator 6.3.1 (also present on current
master)
- Any browser
Description
The built-in
tableclipboard paste parser splits pasted data on\nonly and does not handle\r\nline endings. When pasting data copied from Excel (and most Windows apps), which ends rows with\r\nand adds a trailing\r\nafter the last row, two problems occur:\rfrom each\r\nstays attached to the value of the last column of every row (e.g. a pastedy1becomes"y1\r").\r\nproduces an extra empty trailing row, which — depending onclipboardPasteAction— either inserts a blank row or overwrites the cell below the target with an empty value.This is the same underlying problem reported long ago in #2489, which was closed without a fix (no reproducible example was provided at the time). It still reproduces on 6.3.1 / current
master.Steps to reproduce
clipboard: true.x1\ty1\r\nx2\ty2\r\n.Expected
[["x1","y1"],["x2","y2"]]— clean values, no stray\r, no extra empty row.Actual
Parser produces
[["x1","y1\r"],["x2","y2\r"],[""]]—\rstuck on the last column of each row, plus a trailing empty row.Root cause
src/js/modules/Clipboard/defaults/pasteParsers.js, thetableparser:Suggested fix
Normalize line endings and drop a single trailing blank line before splitting:
For reference, ag-Grid handles this in its clipboard parser by treating
\r\nas a single line break (skipping the\nafter a\r) and removing a trailing blank line (suppressLastEmptyLineOnPaste→removeLastLineIfBlank).Environment
master)