Closed ddooley closed 7 months ago
I tried various experiments in adding a "Paste" option in right click menu. Normally Paste menu item is disabled because Handsontable doesn't think there's anything in its clipboard (self.clipboardCache), but that's because that is not directly connected to system clipboard, which has to be read separately via navigator.clipboard.readText() or navigator.clipboard.read() -> both of which are asynchronous calls which make getting at what system clipboard contains in the moment quite complicated. I set disabled to false just to test various possibilities of getting at system clipboard. Possibly other browser permissions have to be asked for by code as mentioned in https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Interact_with_the_clipboard
contextMenu: [
'copy',
'cut',
{
key: 'paste',
name: 'Paste',
disabled: function () {
/* if (self.clipboardCache.length === 0) {
var test = navigator.clipboard.readText();
self.clipboardCache = test;
console.log("nav1", self.clipboardCache);
.then((stuff) => self.clipboardCache = ...) navigator.clipboard.readText();
// try dummy read write text to somewhere?
}*/
return false; //self.clipboardCache.length === 0;
},
callback: function () {
var plugin = this.getPlugin('copyPaste');
this.listen();
// BUG: It seems like extra lf is added by sheetclip, causing
// empty last row to be added and pasted. Exception is pasting
// of single empty cell
/*
if (self.clipboardCache.length === 0) {
const text = await navigator.clipboard.readText(); //AWAIT isn't allowed here.
console.log("test", test);
self.clipboardCache = self.sheetClip.parse(test);
console.log("nav2", self.clipboardCache);
};
*/
if (self.clipboardCache.length > 0)
self.clipboardCache = self.clipboardCache.slice(0, -1);
plugin.paste(self.clipboardCache);
},
},
'remove_row',
'row_above',
'row_below',
],
I have a hack solution for this that seems to be working, via date field right-click menu paste option. Only drawback is no ctrl-v for pasting on that particular type of field. Uploading shortly.
The Data HandsonTable upgrade to 13.0.1 (now on master branch as DH v.1.6.0) was successful except for one issue, that the lib/editors/FlatpickrEditor.js intercept of cell editing events appears to be preventing dates or other content from being pasted into date columns from the system clipboard. At moment DH allows copy/cut/paste from Handsontable cells, though a bit awkwardly via a right-click-paste menu item. But ctrl-v and ctrl-c don’t work on date columns, and the right click menu paste option doesn’t transfer a system clipboard content into aone or a range of date cells. This means one can’t copy a column of dates from a spreadsheet app directly into the date column of DataHarmonizer / Handsontable app. Oddly if its a multi-column system clipboard content, that DOES paste a long as beginning target cell is not a date column, i.e. one can slip in dates indirectly.
Not quite sure how to solve this. One case to solve for sure is in making a selection of date column cells in DataHarmonizer in order to paste system clipboard values in.