Merge PR #607: Minus after comma is now unary negation
diff --git a/src/commands/math/basicSymbols.js b/src/commands/math/basicSymbols.js
index fd2b851..979ae9d 100644
--- a/src/commands/math/basicSymbols.js
+++ b/src/commands/math/basicSymbols.js
@@ -414,8 +414,11 @@
_.contactWeld = _.siblingCreated = _.siblingDeleted = function(opts, dir) {
if (dir === R) return; // ignore if sibling only changed on the right
+ // If the left sibling is a binary operator or a separator (comma, semicolon, colon)
+ // or an open bracket (open parenthesis, open square bracket)
+ // consider the operator to be unary, otherwise binary
this.jQ[0].className =
- (!this[L] || this[L] instanceof BinaryOperator ? '' : 'mq-binary-operator');
+ (!this[L] || this[L] instanceof BinaryOperator || /^[,;:\(\[]$/.test(this[L].ctrlSeq) ? '' : 'mq-binary-operator');
return this;
};
});
diff --git a/test/unit/css.test.js b/test/unit/css.test.js
index 223895f..b108046 100644
--- a/test/unit/css.test.js
+++ b/test/unit/css.test.js
@@ -52,5 +52,33 @@
var mqF = $(mq.el()).find('.mq-f');
var testVal = parseFloat(mqF.css('margin-right')) - parseFloat(mqF.css('margin-left'));
assert.ok(testVal > 0, 'this should be truthy') ;
+
+ $(mq.el()).remove();
+ });
+
+ test('unary PlusMinus before separator', function () {
+ var mq = MQ.MathField($('<span></span>').appendTo('#mock')[0]);
+ mq.latex('(-1,-1-1)-1,(+1;+1+1)+1,(\\pm1,\\pm1\\pm1)\\pm1');
+ var spans = $(mq.el()).find('.mq-root-block').find('span');
+ assert.equal(spans.length, 35, 'PlusMinus expression parsed incorrectly');
+
+ function isBinaryOperator(i) { return $(spans[i]).hasClass('mq-binary-operator'); }
+ function assertBinaryOperator(i, s) { assert.ok(isBinaryOperator(i), '"' + s + '" should be binary'); }
+ function assertUnaryOperator(i, s) { assert.ok(!isBinaryOperator(i), '"' + s + '" should be unary'); }
+
+ assertUnaryOperator(1, '(-');
+ assertUnaryOperator(4, '(-1,-');
+ assertBinaryOperator(6, '(-1,-1-');
+ assertBinaryOperator(9, '(-1,-1-1)-');
+ assertUnaryOperator(13, '(-1,-1-1)-1,(+');
+ assertUnaryOperator(16, '(-1,-1-1)-1,(+1;+');
+ assertBinaryOperator(18, '(-1,-1-1)-1,(+1;+1+');
+ assertBinaryOperator(21, '(-1,-1-1)-1,(+1;+1+1)+');
+ assertUnaryOperator(25, '(-1,-1-1)-1,(+1;+1+1)+1,(\pm');
+ assertUnaryOperator(28, '(-1,-1-1)-1,(+1;+1+1)+1,(\pm1,\pm');
+ assertBinaryOperator(30, '(-1,-1-1)-1,(+1;+1+1)+1,(\pm1,\pm1\pm');
+ assertBinaryOperator(33, '(-1,-1-1)-1,(+1;+1+1)+1,(\pm1,\pm1\pm1)\pm');
+
+ $(mq.el()).remove();
});
});