[LRN] Add `empty()` public method and `clear()` as its alias Removes all math from the editable field Conflicts: src/commands/math.js src/commands/math/commands.js src/publicapi.js
diff --git a/src/publicapi.js b/src/publicapi.js index 84b13db..35cc936 100644 --- a/src/publicapi.js +++ b/src/publicapi.js
@@ -160,6 +160,10 @@ if (this.__controller.blurred) this.__controller.cursor.hide().parent.blur(); return this; }; + _.empty = _.clear = function() { + this.select().__controller.backspace(); + return this; + }; _.cmd = function(cmd) { var ctrlr = this.__controller.notify(), cursor = ctrlr.cursor; if (/^\\[a-z]+$/i.test(cmd)) {
diff --git a/test/unit/publicapi.test.js b/test/unit/publicapi.test.js index 4395cc8..f208bff 100644 --- a/test/unit/publicapi.test.js +++ b/test/unit/publicapi.test.js
@@ -108,7 +108,7 @@ mq.latex('x+y'); assert.equal(mq.html(), '<var>x</var><span class="mq-binary-operator">+</span><var>y</var>'); }); - + test('.text() with incomplete commands', function() { assert.equal(mq.text(), ''); mq.typedText('\\'); @@ -157,6 +157,18 @@ assert.equal(mq.__controller.cursor[L].ctrlSeq, '0'); assert.equal(mq.__controller.cursor[R], 0); }); + + test('.clear()', function() { + mq.latex('xyz'); + mq.clear(); + assert.equal(mq.latex(), ''); + }); + + test('.empty()', function() { + mq.latex('xyz'); + mq.empty(); + assert.equal(mq.latex(), ''); + }); }); test('edit handler interface versioning', function() {