feat(editor): support atomic multi-cell CSV paste

This commit is contained in:
Anya Tokugawa committed 2026-11-08 21:48:32 +09:00
1 parent 2d6ceac0d7
commit 09afb438c9
7 files changed
+88 -11

No files matched your search

+17
View File
@@ -44,6 +44,23 @@
cell(1,1).focus();button('−→').click();assert(PagesCSV.parse(e.text()).rows[0].cells.length===2,'Column delete failed');
button('↶').click();cell(1,1).focus();button('−↧').click();assert(PagesCSV.parse(e.text()).rows.length===28,'Row delete failed');
button('↶').click();
// Spreadsheet clipboard paste is one atomic undo step, including new rows.
e.setText(original);await e.renderPreview();
const paste=(r,c,text)=>{const data=new DataTransfer();data.setData('text/plain',text);data.setData('text/html','<img src=x onerror=alert(1)>');const target=cell(r,c);target.focus();const event=new ClipboardEvent('paste',{clipboardData:data,bubbles:true,cancelable:true});target.dispatchEvent(event);return event;};
assert(paste(1,0,'first\t"multi\nline"\r\n<img src=x onerror=alert(1)>\t=1+1\r\n').defaultPrevented,'Table paste not intercepted');
const pasted=e.text();assert(PagesCSV.parse(pasted).rows.length===3,'Paste did not grow rows');
assert(cell(1,1).value==='multi\nline','Quoted multiline clipboard broken');
assert(!document.querySelector('.csv-edit-pane img'),'Clipboard HTML executed');
assert(document.activeElement===cell(1,0),'Paste focus lost');
assert(await e.saveNow(),'Pasted CSV save failed');assert((await e.state()).body===pasted,'Pasted CSV not persisted exactly');e.paused=true;
button('↶').click();assert(e.text()===original,'Paste not undone atomically');
button('↷').click();assert(e.text()===pasted,'Paste redo changed bytes');
assert(paste(1,0,'valid\tdata\n"unfinished').defaultPrevented,'Malformed paste fell through');
assert(e.text()===pasted,'Malformed paste partially applied');
assert(paste(1,0,'a\n'.repeat(200)).defaultPrevented,'Oversize paste fell through');
assert(e.text()===pasted,'Oversize paste partially applied');
assert(!paste(1,0,'ordinary, text').defaultPrevented,'Single-cell text paste intercepted');
button('↶').click();assert(e.text()===original,'Rejected paste polluted undo');
const css=getComputedStyle(document.querySelector('.csv-edit-toolbar'));assert(css.color!==css.backgroundColor,'Toolbar lacks contrast');
clearTimeout(e.autosaveTimer);clearInterval(e.stateTimer);e.paused=true;
document.body.dataset.vimReady='true';