Skip to content

Commit

Permalink
simplification of paste fix for date fields
Browse files Browse the repository at this point in the history
No need for self.clipboardCache update, that seems to be done elsewhere.
  • Loading branch information
ddooley committed Nov 7, 2023
1 parent e5550a9 commit a6c4fef
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions lib/DataHarmonizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,28 +511,38 @@ class DataHarmonizer {
key: 'paste',
name: 'Paste',
disabled: function () {
// The only easy way to get system cut+copy buffer contents into
// handsontable is to go query the system cut paste buffer every
// time the right-click menu is presented, and "Paste" option
// enabled.
// For now always on, since we can't query whether something is
// in system cut/paste buffer without prompting user for ok.
return false;
},
callback: function () {
var plugin = this.getPlugin('copyPaste');
this.listen();

// Due to asynchronous clipboard calls, this has to be in an
// immediate setTimeout()
setTimeout(async () => {
const text = await navigator.clipboard.readText();
if (text && text.length) {
self.clipboardCache = text;

// An odd issue that with handsontable Paste menu item,
// targeted paste area gets extended a row on each
// subsequent Paste request. This doesn't happen if one
// uses CTRL-V instead (but that doesn't work on
// FlatpickrEditor fields unless they are towards end
// of multi-column paste).
// See https://github.com/handsontable/handsontable/issues/1930
// Solution is to test for and clear out trailing newline.

if (text.substr(-1, 1) == '\n')
text = text.slice(0, -1);
//self.clipboardCache = text;
plugin.paste(text);
}

});

return false; // For now always on, even if cut/copy buffer is empty.
},
callback: function () {
var plugin = this.getPlugin('copyPaste');
this.listen();
// An odd issue that with handsontable Paste menu item,
// targeted paste area gets extended a row on each subsequent
// Paste request. This doesn't happen if one uses CTRL-V
// instead (but that doesn't work on FlatpickrEditor fields).
// See https://github.com/handsontable/handsontable/issues/1930
// Solution is to test for and clear out trailing newline.
/*
if (
self.clipboardCache &&
self.clipboardCache.length &&
Expand All @@ -542,6 +552,7 @@ class DataHarmonizer {
}
plugin.paste(self.clipboardCache);
*/
},
},
'remove_row',
Expand Down

0 comments on commit a6c4fef

Please sign in to comment.