mzechmeister/csvplotter

Cutting selection over two cells destroys cell

Closed this issue · 1 comments

Making a selection over two cells and cutting it (e.g. backspace, deleteContentBackward), destroys the cell structure.
Traces.oninput deletes cell label and in the textarea new lines are removed.

deleteContentBackward is an oninput event. beforeinput or keydown would be needed to check and handle multicell selections and avoid deletion of cell structure.

Similar, paste is affected but since it is handle in the Traces is not affected in first place, but textarea suffers.

onpaste can be captured.

csvplotter/csv_plotter.htm

Lines 1415 to 1420 in 4b432ab

Traces.onpaste = function (e) {
// console.log("redirect insertFromPaste to ta")
e.preventDefault()
edata = (e.clipboardData || window.clipboardData).getData('Text')
taInsert(edata, ...prev_sel)
}

insertFromPaste (Ctrl-V, mobile paste) and deleteByCut (Ctrl-X) are also present in Traces.oninput

csvplotter/csv_plotter.htm

Lines 1504 to 1508 in 4b432ab

if ("deleteByCut deleteByDrag deleteContentBackward deleteContentForward".includes(e.inputType)) {
ta.setSelectionRange(...prev_sel)
document.execCommand('delete')
}
if ("insertFromDrop insertFromPaste insertText".includes(e.inputType)) {

But it seems, it cannot be reached.

Traces.oninput was introduced in the refactoring

Traces.onpaste = function (e) {

and handled verbosely insertFromPaste and deleteByCut. It was simplified in 9f09ebe.

It likely goes back to
https://gist.github.com/mzechmeister/d0333d6e46746efc2f06e61547d69047/789b850de6b07859ef29e142bdf418b21656c190#file-pseudo_editable_field-html-L126, where onpaste was as simple as

mydiv.onpaste = function (e) {
    // at least for edge, not firefox
    edata = (e.clipboardData || window.clipboardData).getData('Text')
}

and oninput handled everything.