Permalink
Browse files

* Support column-only ranges such as =SUM(A:A) for @artem.

  • Loading branch information...
1 parent 641daeb commit eb5fd79720e9186b560744f544b4cd9d0287aa16 @audreyt committed Feb 16, 2013
Showing with 23 additions and 9 deletions.
  1. +9 −2 SocialCalcModule.js
  2. +7 −2 formula1.js
  3. +2 −0 socialcalc-3.js
  4. +5 −5 static/ethercalc.js
View
@@ -4880,6 +4880,7 @@ SocialCalc.UndoStack.prototype.PushChange = function(type) { // adding a new thi
}
SocialCalc.UndoStack.prototype.AddDo = function() {
+ if (!this.stack[this.stack.length-1]) { return; }
var args = [];
for (var i=0; i<arguments.length; i++) {
if (arguments[i]!=null) args.push(arguments[i]); // ignore null or undefined
@@ -4889,6 +4890,7 @@ SocialCalc.UndoStack.prototype.AddDo = function() {
}
SocialCalc.UndoStack.prototype.AddUndo = function() {
+ if (!this.stack[this.stack.length-1]) { return; }
var args = [];
for (var i=0; i<arguments.length; i++) {
if (arguments[i]!=null) args.push(arguments[i]); // ignore null or undefined
@@ -15613,7 +15615,7 @@ SocialCalc.Formula.OperandsAsRangeOnSheet = function(sheet, operand) {
}
if (value2.type == "name") { // coord:name is allowed, if name is just one cell
- value2 = scf.LookupName(othersheet, value2.value);
+ value2 = scf.LookupName(othersheet, value2.value, "end");
}
if (value2.type == "coord") { // value is a coord reference, so return the combined range
@@ -15687,7 +15689,7 @@ SocialCalc.Formula.OperandAsSheetName = function(sheet, operand) {
// Note: The range must not have sheet names ("!") in them.
//
-SocialCalc.Formula.LookupName = function(sheet, name) {
+SocialCalc.Formula.LookupName = function(sheet, name, isEnd) {
var pos, specialc, parseinfo;
var names = sheet.names;
@@ -15743,6 +15745,11 @@ SocialCalc.Formula.LookupName = function(sheet, name) {
value.type = specialc.substring(pos+1);
return value;
}
+ else if (/^[a-zA-Z][a-zA-Z]?$/.test(name)) {
+ value.type = "coord";
+ value.value = name.toUpperCase() + (isEnd ? sheet.attribs.lastrow : 1);
+ return value;
+ }
else {
value.value = "";
value.type = "e#NAME?";
View
@@ -1256,7 +1256,7 @@ SocialCalc.Formula.OperandsAsRangeOnSheet = function(sheet, operand) {
}
if (value2.type == "name") { // coord:name is allowed, if name is just one cell
- value2 = scf.LookupName(othersheet, value2.value);
+ value2 = scf.LookupName(othersheet, value2.value, "end");
}
if (value2.type == "coord") { // value is a coord reference, so return the combined range
@@ -1330,7 +1330,7 @@ SocialCalc.Formula.OperandAsSheetName = function(sheet, operand) {
// Note: The range must not have sheet names ("!") in them.
//
-SocialCalc.Formula.LookupName = function(sheet, name) {
+SocialCalc.Formula.LookupName = function(sheet, name, isEnd) {
var pos, specialc, parseinfo;
var names = sheet.names;
@@ -1386,6 +1386,11 @@ SocialCalc.Formula.LookupName = function(sheet, name) {
value.type = specialc.substring(pos+1);
return value;
}
+ else if (/^[a-zA-Z][a-zA-Z]?$/.test(name)) {
+ value.type = "coord";
+ value.value = name.toUpperCase() + (isEnd ? sheet.attribs.lastrow : 1);
+ return value;
+ }
else {
value.value = "";
value.type = "e#NAME?";
View
@@ -4022,6 +4022,7 @@ SocialCalc.UndoStack.prototype.PushChange = function(type) { // adding a new thi
}
SocialCalc.UndoStack.prototype.AddDo = function() {
+ if (!this.stack[this.stack.length-1]) { return; }
var args = [];
for (var i=0; i<arguments.length; i++) {
if (arguments[i]!=null) args.push(arguments[i]); // ignore null or undefined
@@ -4031,6 +4032,7 @@ SocialCalc.UndoStack.prototype.AddDo = function() {
}
SocialCalc.UndoStack.prototype.AddUndo = function() {
+ if (!this.stack[this.stack.length-1]) { return; }
var args = [];
for (var i=0; i<arguments.length; i++) {
if (arguments[i]!=null) args.push(arguments[i]); // ignore null or undefined
View
@@ -166,8 +166,8 @@ y;u.calclistlength++;y=x;x=r[y]?r[y].oldcoord:null}return""};SocialCalc.Parse=fu
SocialCalc.Parse.prototype.RestOfString=function(){var a=this.pos;if(0>this.pos||this.pos>=this.lineEnd)return"";this.pos=this.lineEnd;return this.str.substring(a,this.lineEnd)};SocialCalc.Parse.prototype.RestOfStringNoMove=function(){return 0>this.pos||this.pos>=this.lineEnd?"":this.str.substring(this.pos,this.lineEnd)};SocialCalc.Parse.prototype.NextLine=function(){this.pos=this.lineEnd+1;this.lineEnd=this.str.indexOf("\n",this.pos);0>this.lineEnd&&(this.lineEnd=this.str.length)};
SocialCalc.Parse.prototype.EOF=function(){return 0>this.pos||this.pos>=this.str.length?!0:!1};SocialCalc.UndoStack=function(){this.stack=[];this.tos=-1;this.maxRedo=0;this.maxUndo=50};
SocialCalc.UndoStack.prototype.PushChange=function(a){for(;0<this.stack.length&&this.stack.length-1>this.tos;)this.stack.pop();this.stack.push({command:[],type:a,undo:[]});this.maxRedo&&this.stack.length>this.maxRedo&&this.stack.shift();this.maxUndo&&this.stack.length>this.maxUndo&&(this.stack[this.stack.length-this.maxUndo-1].undo=[]);this.tos=this.stack.length-1};
-SocialCalc.UndoStack.prototype.AddDo=function(){for(var a=[],c=0;c<arguments.length;c++)null!=arguments[c]&&a.push(arguments[c]);this.stack[this.stack.length-1].command.push(a.join(" "))};SocialCalc.UndoStack.prototype.AddUndo=function(){for(var a=[],c=0;c<arguments.length;c++)null!=arguments[c]&&a.push(arguments[c]);this.stack[this.stack.length-1].undo.push(a.join(" "))};SocialCalc.UndoStack.prototype.TOS=function(){return 0<=this.tos?this.stack[this.tos]:null};
-SocialCalc.UndoStack.prototype.Undo=function(){return 0<=this.tos&&(!this.maxUndo||this.tos>this.stack.length-this.maxUndo-1)?(this.tos-=1,!0):!1};SocialCalc.UndoStack.prototype.Redo=function(){return this.tos<this.stack.length-1?(this.tos+=1,!0):!1};SocialCalc.Clipboard={clipboard:""};
+SocialCalc.UndoStack.prototype.AddDo=function(){if(this.stack[this.stack.length-1]){for(var a=[],c=0;c<arguments.length;c++)null!=arguments[c]&&a.push(arguments[c]);this.stack[this.stack.length-1].command.push(a.join(" "))}};SocialCalc.UndoStack.prototype.AddUndo=function(){if(this.stack[this.stack.length-1]){for(var a=[],c=0;c<arguments.length;c++)null!=arguments[c]&&a.push(arguments[c]);this.stack[this.stack.length-1].undo.push(a.join(" "))}};
+SocialCalc.UndoStack.prototype.TOS=function(){return 0<=this.tos?this.stack[this.tos]:null};SocialCalc.UndoStack.prototype.Undo=function(){return 0<=this.tos&&(!this.maxUndo||this.tos>this.stack.length-this.maxUndo-1)?(this.tos-=1,!0):!1};SocialCalc.UndoStack.prototype.Redo=function(){return this.tos<this.stack.length-1?(this.tos+=1,!0):!1};SocialCalc.Clipboard={clipboard:""};
SocialCalc.RenderContext=function(a){var c=a.attribs,b=SocialCalc.Constants;this.sheetobj=a;this.showRCHeaders=this.showGrid=this.hideRowsCols=!1;this.rownamewidth=b.defaultRowNameWidth;this.pixelsPerRow=b.defaultAssumedRowHeight;this.cellskip={};this.coordToCR={};this.colwidth=[];this.totalwidth=0;this.rowpanes=[];this.colpanes=[];this.colunhideleft=[];this.colunhideright=[];this.rowunhidetop=[];this.rowunhidebottom=[];this.maxrow=this.maxcol=0;this.highlights={};this.cursorsuffix="";this.highlightTypes=
{cursor:{style:b.defaultHighlightTypeCursorStyle,className:b.defaultHighlightTypeCursorClass},range:{style:b.defaultHighlightTypeRangeStyle,className:b.defaultHighlightTypeRangeClass},cursorinsertup:{style:"color:#FFF;backgroundColor:#A6A6A6;backgroundRepeat:repeat-x;backgroundPosition:top left;backgroundImage:url("+b.defaultImagePrefix+"cursorinsertup.gif);",className:b.defaultHighlightTypeCursorClass},cursorinsertleft:{style:"color:#FFF;backgroundColor:#A6A6A6;backgroundRepeat:repeat-y;backgroundPosition:top left;backgroundImage:url("+
b.defaultImagePrefix+"cursorinsertleft.gif);",className:b.defaultHighlightTypeCursorClass},range2:{style:"color:#000;backgroundColor:#FFF;backgroundImage:url("+b.defaultImagePrefix+"range2.gif);",className:""}};this.cellIDprefix=b.defaultCellIDPrefix;this.defaultlinkstyle=null;this.defaultHTMLlinkstyle={type:"html"};this.defaultfontstyle=b.defaultCellFontStyle;this.defaultfontsize=b.defaultCellFontSize;this.defaultfontfamily=b.defaultCellFontFamily;this.defaultlayout=b.defaultCellLayout;this.defaultpanedividerwidth=
@@ -549,10 +549,10 @@ SocialCalc.Formula.OperandAsCoord=function(a,c){var b={type:"",value:""},d=c.len
SocialCalc.Formula.OperandsAsCoordOnSheet=function(a,c){var b,d,e,f={},g={};e=SocialCalc.Formula;b=c.length;f.value=c[b-1].value;f.type=c[b-1].type;c.pop();b=e.OperandAsSheetName(a,c);d=e.FindInSheetCache(b.value);if(null==d)return g.type="e#REF!",g.value=0,g.error=SocialCalc.Constants.s_sheetunavailable+" "+b.value,g;"name"==f.type&&(f=e.LookupName(d,f.value));g.type=f.type;"coord"==f.type?g.value=f.value+"!"+b.value:"range"==f.type?(e=f.value.indexOf("|"),d=f.value.indexOf("|",e+1),g.value=f.value.substring(0,
e)+"!"+b.value+"|"+f.value.substring(e+1,d)+"|"):"e"==f.type.charAt(0)?g.value=f.value:(g.error=SocialCalc.Constants.s_calcerrcellrefmissing,g.type="e#REF!",g.value=0);return g};
SocialCalc.Formula.OperandsAsRangeOnSheet=function(a,c){var b,d,e,f,g={},l=SocialCalc.Formula,h=SocialCalc.Constants;b=c.length;g.value=c[b-1].value;g.type=c[b-1].type;c.pop();b=l.OperandAsCoord(a,c);if("coord"!=b.type)return{value:0,type:"e#REF!"};d=a;e=b.value.indexOf("!");if(-1!=e&&(f=b.value.indexOf("|",e+1),0>f&&(f=b.value.length),d=l.FindInSheetCache(b.value.substring(e+1,f)),null==d))return{value:0,type:"e#REF!",errortext:h.s_sheetunavailable+" "+b.value.substring(e+1,f)};"name"==g.type&&(g=
-l.LookupName(d,g.value));return"coord"==g.type?{value:b.value+"|"+g.value+"|",type:"range"}:{value:h.s_calcerrcellrefmissing,type:"e#REF!"}};
+l.LookupName(d,g.value,"end"));return"coord"==g.type?{value:b.value+"|"+g.value+"|",type:"range"}:{value:h.s_calcerrcellrefmissing,type:"e#REF!"}};
SocialCalc.Formula.OperandAsSheetName=function(a,c){var b,d={type:"",value:""};b=c.length;d.value=c[b-1].value;d.type=c[b-1].type;c.pop();if("name"==d.type){b=SocialCalc.Formula.LookupName(a,d.value);if(!b.value)return d;d.value=b.value;d.type=b.type}"coord"==d.type&&((b=a.cells[SocialCalc.Formula.PlainCoord(d.value)])?(d.value=b.datavalue,d.type=b.valuetype):(d.value="",d.type="b"));"t"!=d.type.charAt(0)&&(d.value="",d.error=SocialCalc.Constants.s_calcerrsheetnamemissing);return d};
-SocialCalc.Formula.LookupName=function(a,c){var b,d,e;d=a.names;e={};b=!1;if(d[c.toUpperCase()]){e.value=d[c.toUpperCase()].definition;if("="==e.value.charAt(0)){if(a.checknamecirc){if(a.checknamecirc[c])return e.type="e#NAME?",e.error=SocialCalc.Constants.s_circularnameref+' "'+c+'".',e}else a.checknamecirc={},b=!0;a.checknamecirc[c]=!0;e=SocialCalc.Formula.ParseFormulaIntoTokens(e.value.substring(1));e=SocialCalc.Formula.evaluate_parsed_formula(e,a,1);delete a.checknamecirc[c];b&&delete a.checknamecirc;
-if("range"!=e.type)return e}b=e.value.indexOf(":");-1!=b?(e.type="range",e.value=e.value.substring(0,b)+"|"+e.value.substring(b+1)+"|"):e.type="coord";e.value=e.value.toUpperCase()}else(d=SocialCalc.Formula.SpecialConstants[c.toUpperCase()])?(b=d.indexOf(","),e.value=d.substring(0,b)-0,e.type=d.substring(b+1)):(e.value="",e.type="e#NAME?",e.error=SocialCalc.Constants.s_calcerrunknownname+' "'+c+'"');return e};
+SocialCalc.Formula.LookupName=function(a,c,b){var d,e,f=a.names;e={};d=!1;if(f[c.toUpperCase()]){e.value=f[c.toUpperCase()].definition;if("="==e.value.charAt(0)){if(a.checknamecirc){if(a.checknamecirc[c])return e.type="e#NAME?",e.error=SocialCalc.Constants.s_circularnameref+' "'+c+'".',e}else a.checknamecirc={},d=!0;a.checknamecirc[c]=!0;e=SocialCalc.Formula.ParseFormulaIntoTokens(e.value.substring(1));e=SocialCalc.Formula.evaluate_parsed_formula(e,a,1);delete a.checknamecirc[c];d&&delete a.checknamecirc;
+if("range"!=e.type)return e}a=e.value.indexOf(":");-1!=a?(e.type="range",e.value=e.value.substring(0,a)+"|"+e.value.substring(a+1)+"|"):e.type="coord";e.value=e.value.toUpperCase()}else(d=SocialCalc.Formula.SpecialConstants[c.toUpperCase()])?(a=d.indexOf(","),e.value=d.substring(0,a)-0,e.type=d.substring(a+1)):/^[a-zA-Z][a-zA-Z]?$/.test(c)?(e.type="coord",e.value=c.toUpperCase()+(b?a.attribs.lastrow:1)):(e.value="",e.type="e#NAME?",e.error=SocialCalc.Constants.s_calcerrunknownname+' "'+c+'"');return e};
SocialCalc.Formula.StepThroughRangeDown=function(a,c){var b,d,e,f,g,l,h,n,q=SocialCalc.Formula;f=c.indexOf("|");e=c.indexOf("|",f+1);b=c.substring(0,f);d=c.substring(f+1,e);e=c.substring(e+1)-0;f=b.indexOf("!");-1!=f?(g=b.substring(f),b=b.substring(0,f)):g="";f=d.indexOf("!");-1!=f&&(d=d.substring(0,f));f=q.OrderRangeParts(b,d);n=0;for(h=f.r1;h<=f.r2;h++)for(l=f.c1;l<=f.c2;l++)if(n++,n>e)return(h!=f.r2||l!=f.c2)&&q.PushOperand(a,"range",b+g+"|"+d+"|"+n),{value:SocialCalc.crToCoord(l,h)+g,type:"coord"}};
SocialCalc.Formula.DecodeRangeParts=function(a,c){var b,d,e,f,g=SocialCalc.Formula;e=c.indexOf("|");f=c.indexOf("|",e+1);b=c.substring(0,e);d=c.substring(e+1,f);e=b.indexOf("!");-1!=e?(f=b.substring(e+1),b=b.substring(0,e)):f="";e=d.indexOf("!");-1!=e&&(d=d.substring(0,e));e=a;if(f&&(e=g.FindInSheetCache(f),null==e))return null;b=g.OrderRangeParts(b,d);return{sheetdata:e,sheetname:f,col1num:b.c1,ncols:b.c2-b.c1+1,row1num:b.r1,nrows:b.r2-b.r1+1}};
SocialCalc.Formula.FunctionList||(SocialCalc.Formula.FunctionList={});SocialCalc.Formula.FunctionClasses=null;SocialCalc.Formula.FunctionArgDefs={};

0 comments on commit eb5fd79

Please sign in to comment.