(core) Check document ID when parsing pasted references

Summary: Add doc-id attribute to copied HTML columns next to column type. Only use the raw value (rather than the display value) when the parsed doc-id from pasted HTML matches the current document ID, similar to ensuring that the type matches. This only applies to references and reflists.

Test Plan: Extended CopyPaste.ts

Reviewers: dsagal

Reviewed By: dsagal

Subscribers: paulfitz

Differential Revision: https://phab.getgrist.com/D3154
This commit is contained in:
Alex Hall
2021-11-29 21:38:05 +02:00
parent 482ce0e4c4
commit 551ea28fc4
3 changed files with 50 additions and 3 deletions

View File

@@ -373,12 +373,17 @@ BaseView.prototype._parsePasteForView = function(data, fields) {
const updateColIds = updateCols.map(c => c && c.colId());
const updateColTypes = updateCols.map(c => c && c.type());
const parsers = fields.map(field => field && field.valueParser() || (x => x));
const docIdHash = tableUtil.getDocIdHash();
const richData = data.map((col, idx) => {
if (!col.length) {
return col;
}
const typeMatches = col[0] && col[0].colType === updateColTypes[idx];
const typeMatches = col[0] && col[0].colType === updateColTypes[idx] && (
// When copying references, only use the row ID (raw value) when copying within the same document
// to avoid referencing the wrong rows.
col[0].docIdHash === docIdHash || !gristTypes.isFullReferencingType(updateColTypes[idx])
);
const parser = parsers[idx];
return col.map(v => {
if (v) {