#750: New API method .empty()
Supersedes #553
diff --git a/src/publicapi.js b/src/publicapi.js
index 84b13db..63cd46f 100644
--- a/src/publicapi.js
+++ b/src/publicapi.js
@@ -160,6 +160,15 @@
if (this.__controller.blurred) this.__controller.cursor.hide().parent.blur();
return this;
};
+ _.empty = function() {
+ var root = this.__controller.root, cursor = this.__controller.cursor;
+ root.eachChild('postOrder', 'dispose');
+ root.ends[L] = root.ends[R] = 0;
+ root.jQ.empty();
+ delete cursor.selection;
+ cursor.insAtRightEnd(root);
+ 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..8c1d8bb 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,12 @@
assert.equal(mq.__controller.cursor[L].ctrlSeq, '0');
assert.equal(mq.__controller.cursor[R], 0);
});
+
+ test('.empty()', function() {
+ mq.latex('xyz');
+ mq.empty();
+ assert.equal(mq.latex(), '');
+ });
});
test('edit handler interface versioning', function() {