Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify drag'n fill command behaviour to fix audreyt/ethercalc#769. #52

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ var css_files = [
css_folder + 'socialcalc.css'
];

gulp.task('validate-js', function () {
function validate_js() {
for (js_file of filesExist(js_files)) {
gulp.src(js_file)
.pipe(jshint())
.pipe(jshint({"asi": true, "maxerr": 222}))
.pipe(jshint.reporter('jshint-stylish'));
}

Expand All @@ -39,20 +39,20 @@ gulp.task('validate-js', function () {
.pipe(concat('module-wrapper.js'))
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
};

gulp.task('js', ['validate-js'], function () {
function make_js() {
var files = filesExist([].concat(js_top_file, js_files, js_bottom_file));
return gulp.src(files)
.pipe(concat('SocialCalc.js'))
.pipe(gulp.dest(dist_folder));
});
};

gulp.task('css', function () {
function make_css() {
var files = filesExist(css_files);
return gulp.src(files)
.pipe(concat('socialcalc.css'))
.pipe(gulp.dest(dist_folder));
});
};

gulp.task('default', ['js', 'css'], function () {});
exports.default = gulp.series(validate_js, make_js, make_css);
83 changes: 29 additions & 54 deletions dist/SocialCalc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3085,46 +3085,18 @@ SocialCalc.ExecuteSheetCommand = function(sheet, cmd, saveundo) {
sheet.changedrendervalues = true;
if (saveundo) changes.AddUndo("changedrendervalues"); // to take care of undone pasted spans
what = cmd.NextToken();
var inc = cmd.NextToken();
rest = cmd.RestOfString();
ParseRange();
function increment_amount(down) {
function valid_datatype(type) {
return type == "v" || type == "c";
}
var editor = SocialCalc.GetSpreadsheetControlObject().editor;
var range = editor.range2;
var returnval = undefined;
if (range.hasrange) {
var startcell, endcell;
if (down && (range.bottom - range.top == 1) && range.left == range.right) {
startcell = sheet.GetAssuredCell(SocialCalc.crToCoord(range.left, range.top));
endcell = sheet.GetAssuredCell(SocialCalc.crToCoord(range.left, range.bottom));
if (valid_datatype(startcell.datatype) && valid_datatype(endcell.datatype)) {
returnval = endcell.datavalue - startcell.datavalue;
}
} else if (!down && range.left != range.right) {
startcell = sheet.GetAssuredCell(SocialCalc.crToCoord(range.left, range.top));
endcell = sheet.GetAssuredCell(SocialCalc.crToCoord(range.right, range.top));
if (valid_datatype(startcell.datatype) && valid_datatype(endcell.datatype)) {
returnval = endcell.datavalue - startcell.datavalue;
}
}
}
editor.Range2Remove();
return returnval;
}
var inc;
if (cmd1 == "fillright") {
fillright = true;
rowstart = cr1.row;
colstart = cr1.col + 1;
inc = increment_amount(false);
}
else {
fillright = false;
rowstart = cr1.row + 1;
colstart = cr1.col;
inc = increment_amount(true);
}
for (row = rowstart; row <= cr2.row; row++) {
for (col = colstart; col <= cr2.col; col++) {
Expand Down Expand Up @@ -7402,7 +7374,6 @@ SocialCalc.SetConvertedCell = function(sheet, cr, rawvalue) {

}


//
// SocialCalcTableEditor
//
Expand Down Expand Up @@ -12281,30 +12252,33 @@ SocialCalc.CellHandlesMouseUp = function(e) {
case "Fill":
case "FillC":

crstart = SocialCalc.coordToCr(cellhandles.startingcoord);
crend = SocialCalc.coordToCr(result.coord);
if (cellhandles.filltype) {
if (cellhandles.filltype=="Down") {
crend.col = crstart.col;
var increment = 0;
if ( (editor.range2.left != editor.range2.right) || (editor.range2.top != editor.range2.bottom) ) {
var sheet = editor.context.sheetobj;
var startCell = sheet.GetAssuredCell(SocialCalc.crToCoord(editor.range.left, editor.range.top));
var endCell = startCell;
if (cellhandles.filltype) {
if (cellhandles.filltype=="Down") {
endCell = sheet.GetAssuredCell(SocialCalc.crToCoord(editor.range.left, editor.range.top+1));
}
else {
crend.row = crstart.row;
else if (cellhandles.filltype=="Right") {
endCell = sheet.GetAssuredCell(SocialCalc.crToCoord(editor.range.left+1, editor.range.top));
}
}
result.coord = SocialCalc.crToCoord(crend.col, crend.row);

editor.MoveECell(result.coord);
editor.RangeExtend();
if ( (startCell.datatype == "v" || startCell.datatype == "c")
&& (endCell.datatype == "v" || endCell.datatype == "c")) {
increment = endCell.datavalue - startCell.datavalue;
}
}
}
editor.Range2Remove();

if (editor.cellhandles.filltype=="Right") {
cmdtype = "right";
}
else {
cmdtype = "down";
}
cstr = "fill"+cmdtype+" "+SocialCalc.crToCoord(editor.range.left, editor.range.top)+
":"+SocialCalc.crToCoord(editor.range.right, editor.range.bottom)+cmdtype2;
editor.EditorScheduleSheetCommands(cstr, true, false);
commandStr = "fill" + cellhandles.filltype.toLowerCase()
+ " " + SocialCalc.crToCoord(editor.range.left, editor.range.top)
+ ":" + SocialCalc.crToCoord(editor.range.right, editor.range.bottom)
+ " " + increment
+ cmdtype2;
editor.EditorScheduleSheetCommands(commandStr, true, false);

break;

case "Move":
Expand Down Expand Up @@ -13832,8 +13806,6 @@ SocialCalc.ProcessKey = function (ch, e) {
return ft.EditorProcessKey(ch, e);
}



//
/*
// SocialCalc Number Formatting Library
Expand Down Expand Up @@ -24678,6 +24650,8 @@ SocialCalc.DoCmd = function(obj, which) {
var spreadsheet = SocialCalc.GetSpreadsheetControlObject();
var editor = spreadsheet.editor;

console.log("DoCmd : which :\n", which); // DEBUG STUFF

switch (which) {
case "undo":
spreadsheet.ExecuteCommand("undo", "");
Expand Down Expand Up @@ -25090,6 +25064,8 @@ SocialCalc.SpreadsheetControlExecuteCommand = function(obj, combostr, sstr) {
var spreadsheet = SocialCalc.GetSpreadsheetControlObject();
var eobj = spreadsheet.editor;

console.log("SCEC : combostr : " + combostr + "\n\tsstr : " + sstr); // DEBUG STUFF
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These probably should be removed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree. How should I do this ? Push a new commit on top of this one or amend this one and force push or something else ?


var str = {};
str.P = "%";
str.N = "\n"
Expand Down Expand Up @@ -26916,7 +26892,6 @@ SocialCalc.CtrlSEditorDone = function(idprefix, whichpart) {

}


//
// SocialCalcViewer
//
Expand Down
30 changes: 1 addition & 29 deletions js/socialcalc-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -2181,46 +2181,18 @@ SocialCalc.ExecuteSheetCommand = function(sheet, cmd, saveundo) {
sheet.changedrendervalues = true;
if (saveundo) changes.AddUndo("changedrendervalues"); // to take care of undone pasted spans
what = cmd.NextToken();
var inc = cmd.NextToken();
rest = cmd.RestOfString();
ParseRange();
function increment_amount(down) {
function valid_datatype(type) {
return type == "v" || type == "c";
}
var editor = SocialCalc.GetSpreadsheetControlObject().editor;
var range = editor.range2;
var returnval = undefined;
if (range.hasrange) {
var startcell, endcell;
if (down && (range.bottom - range.top == 1) && range.left == range.right) {
startcell = sheet.GetAssuredCell(SocialCalc.crToCoord(range.left, range.top));
endcell = sheet.GetAssuredCell(SocialCalc.crToCoord(range.left, range.bottom));
if (valid_datatype(startcell.datatype) && valid_datatype(endcell.datatype)) {
returnval = endcell.datavalue - startcell.datavalue;
}
} else if (!down && range.left != range.right) {
startcell = sheet.GetAssuredCell(SocialCalc.crToCoord(range.left, range.top));
endcell = sheet.GetAssuredCell(SocialCalc.crToCoord(range.right, range.top));
if (valid_datatype(startcell.datatype) && valid_datatype(endcell.datatype)) {
returnval = endcell.datavalue - startcell.datavalue;
}
}
}
editor.Range2Remove();
return returnval;
}
var inc;
if (cmd1 == "fillright") {
fillright = true;
rowstart = cr1.row;
colstart = cr1.col + 1;
inc = increment_amount(false);
}
else {
fillright = false;
rowstart = cr1.row + 1;
colstart = cr1.col;
inc = increment_amount(true);
}
for (row = rowstart; row <= cr2.row; row++) {
for (col = colstart; col <= cr2.col; col++) {
Expand Down
45 changes: 24 additions & 21 deletions js/socialcalctableeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4876,30 +4876,33 @@ SocialCalc.CellHandlesMouseUp = function(e) {
case "Fill":
case "FillC":

crstart = SocialCalc.coordToCr(cellhandles.startingcoord);
crend = SocialCalc.coordToCr(result.coord);
if (cellhandles.filltype) {
if (cellhandles.filltype=="Down") {
crend.col = crstart.col;
var increment = 0;
if ( (editor.range2.left != editor.range2.right) || (editor.range2.top != editor.range2.bottom) ) {
var sheet = editor.context.sheetobj;
var startCell = sheet.GetAssuredCell(SocialCalc.crToCoord(editor.range.left, editor.range.top));
var endCell = startCell;
if (cellhandles.filltype) {
if (cellhandles.filltype=="Down") {
endCell = sheet.GetAssuredCell(SocialCalc.crToCoord(editor.range.left, editor.range.top+1));
}
else {
crend.row = crstart.row;
else if (cellhandles.filltype=="Right") {
endCell = sheet.GetAssuredCell(SocialCalc.crToCoord(editor.range.left+1, editor.range.top));
}
}
result.coord = SocialCalc.crToCoord(crend.col, crend.row);

editor.MoveECell(result.coord);
editor.RangeExtend();
if ( (startCell.datatype == "v" || startCell.datatype == "c")
&& (endCell.datatype == "v" || endCell.datatype == "c")) {
increment = endCell.datavalue - startCell.datavalue;
}
}
}
editor.Range2Remove();

if (editor.cellhandles.filltype=="Right") {
cmdtype = "right";
}
else {
cmdtype = "down";
}
cstr = "fill"+cmdtype+" "+SocialCalc.crToCoord(editor.range.left, editor.range.top)+
":"+SocialCalc.crToCoord(editor.range.right, editor.range.bottom)+cmdtype2;
editor.EditorScheduleSheetCommands(cstr, true, false);
commandStr = "fill" + cellhandles.filltype.toLowerCase()
+ " " + SocialCalc.crToCoord(editor.range.left, editor.range.top)
+ ":" + SocialCalc.crToCoord(editor.range.right, editor.range.bottom)
+ " " + increment
+ cmdtype2;
editor.EditorScheduleSheetCommands(commandStr, true, false);

break;

case "Move":
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
},
"homepage": "https://github.com/marcelklehr/socialcalc#readme",
"devDependencies": {
"gulp": "^3.9.1",
"gulp-jshint": "^2.0.4",
"jshint": "^2.9.5",
"jshint-stylish": "^2.2.1",
"gulp-uglify": "^3.0.0",
"gulp-concat": "^2.6.1",
"files-exist": "^1.0.2"
"files-exist": "1.0.2",
"gulp": "4.0.2",
"gulp-concat": "2.6.1",
"gulp-jshint": "2.0.4",
"gulp-uglify": "3.0.0",
"jshint": "2.9.5",
"jshint-stylish": "2.2.1"
}
}