Skip to content

Commit

Permalink
4.14.0 align version, including expanded paste
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul committed Oct 7, 2024
1 parent 7b213f7 commit 4682ef2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6453,6 +6453,23 @@ if (! formula && typeof(require) === 'function') {
*/
obj.paste = function(x, y, data) {
// Paste filter
var x_1 = parseInt(x),
y_1 = parseInt(y),
x_2 = parseInt(obj.selectedCell[2]),
y_2 = parseInt(obj.selectedCell[3]),
w = x_2 - x_1 + 1,
h = y_2 - y_1 + 1;

// change paste range if select is from right to left
if (x_2 < x_1){
x = x_2.toString();
w = x_1 - x_2 + 1;
}
// change paste range if select is from down to up
if (y_2 < y_1){
y = y_2.toString();
h = y_1 - y_2 + 1;
}
var ret = obj.dispatch('onbeforepaste', el, data, x, y);

if (ret === false) {
Expand All @@ -6473,6 +6490,28 @@ if (! formula && typeof(require) === 'function') {
// Split new line
var data = obj.parseCSV(data, "\t");

// Modify data to allow wor extending paste range in multiples of input range
if ((w > 1) & Number.isInteger(w / data[0].length)) {
style = null;
repeats = w / data[0].length;

var arrayB = data.map(function (row, i) {
var arrayC = Array.apply(null, { length: repeats * row.length }).map(
function (e, i) { return row[i % row.length]; }
);
return arrayC;
});
data = arrayB;
}
if ((h > 1) & Number.isInteger(h / data.length)) {
style = null;
var repeats = h / data.length;
var arrayB = Array.apply(null, { length: repeats * data.length }).map(
function (e, i) { return data[i % data.length]; }
);
data = arrayB;
}

if (x != null && y != null && data) {
// Records
var i = 0;
Expand Down

0 comments on commit 4682ef2

Please sign in to comment.