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

+8 -2
View File
@@ -44,6 +44,11 @@
if(cell){const input=el('textarea');input.value=cell.value;input.rows=cell.value.includes('\n')?3:1;input.spellcheck=false;input.dataset.row=r;input.dataset.column=c;input.ariaLabel=this.t(`Row ${r+1}, column ${c+1}`,`${r+1}行 ${c+1}列`);
input.addEventListener('focus',()=>{this.selected=[r,c];this.deleteRow.disabled=this.deleteColumn.disabled=false;});
input.addEventListener('input',()=>this.change('cell',r,c,input.value,input));td.append(input);
input.addEventListener('paste',event=>{
const text=event.clipboardData?.getData('text/plain');
if(typeof text!=='string'||!/[\t\r\n]/.test(text))return;
event.preventDefault();this.change('paste',r,c,text);
});
}
tr.append(td);
}
@@ -55,7 +60,7 @@
const source=this.editor.text();
if(source!==this.last){this.last=null;this.render(source);return;}
try{
const next=PagesCSV.edit(source,action,row,column,value);if(next===source)return;
const next=action==='paste'?PagesCSV.paste(source,row,column,value):PagesCSV.edit(source,action,row,column,value);if(next===source)return;
this.undo.push({before:source,after:next});if(this.undo.length>20)this.undo.shift();this.redo=[];
if(action==='cell'){
// Keep the active textarea and its caret; delayed preview is a no-op.
@@ -64,10 +69,11 @@
}else{
if(action==='add-row')this.page=Math.floor((PagesCSV.parse(next).rows.length-1)/pageSize);
this.last=null;this.editor.setText(next);this.render(next);
if(action==='paste')this.editor.preview.querySelector(`textarea[data-row="${row}"][data-column="${column}"]`)?.focus();
}
}catch{
if(input)input.value=this.model.rows[row].cells[column].value;
this.message.textContent=this.t('Edit exceeds CSV limits. Source retained.','CSVの上限を超えます。元の内容を保持しました。');
this.message.textContent=action==='paste'?this.t('Paste rejected: invalid tab-separated data or CSV limits exceeded. Source retained.','貼り付けできません。タブ区切りデータの形式またはCSVの上限を確認してください。元の内容を保持しました。'):this.t('Edit exceeds CSV limits. Source retained.','CSVの上限を超えます。元の内容を保持しました。');
}
}
history(forward){