From e467bdf8f6f03398d95e650f2154341c95892475 Mon Sep 17 00:00:00 2001 From: Dmitry Mazurov Date: Wed, 18 Mar 2020 17:14:54 +0300 Subject: [PATCH] Added function cursorActivity fot cursor. Signed-off-by: Dmitry Mazurov --- src/js/easymde.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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);