diff --git a/src/js/easymde.js b/src/js/easymde.js index f498a50..28ec7ef 100644 --- a/src/js/easymde.js +++ b/src/js/easymde.js @@ -2378,11 +2378,12 @@ EasyMDE.prototype.createStatusbar = function (status) { // Set up the built-in items var items = []; - var i, onUpdate, defaultValue, dataSet; + var i, onUpdate, onCursorActivity, defaultValue, dataSet; for (i = 0; i < status.length; i++) { // Reset some values onUpdate = undefined; + onCursorActivity = undefined; defaultValue = undefined; dataSet = undefined; @@ -2394,6 +2395,7 @@ EasyMDE.prototype.createStatusbar = function (status) { dataSet: status[i].dataSet, defaultValue: status[i].defaultValue, onUpdate: status[i].onUpdate, + onCursorActivity: status[i].onCursorActivity, }); } else { var name = status[i]; @@ -2424,6 +2426,11 @@ EasyMDE.prototype.createStatusbar = function (status) { var pos = cm.getCursor(); el.innerHTML = pos.line + ':' + pos.ch; }; + onCursorActivity = function (el) { + var pos = cm.getCursor(); + + el.innerHTML = pos.line + ':' + pos.ch; + }; } else if (name === 'autosave') { defaultValue = function (el) { if (options.autosave != undefined && options.autosave.enabled === true) { @@ -2482,6 +2489,16 @@ EasyMDE.prototype.createStatusbar = function (status) { }(el, item))); } + // Ensure the onCursorActivity is a function + if (typeof item.onCursorActivity === 'function') { + // Create a closure around the span of the current action, then execute the onCursorActivity handler + this.codemirror.on('cursorActivity', (function (el, item) { + return function () { + item.onCursorActivity(el); + }; + }(el, item))); + } + // Append the item to the status bar bar.appendChild(el);