From 24d4cc87af6ba7c81bcf5eabfc0cba748bcfe051 Mon Sep 17 00:00:00 2001 From: firm1 Date: Wed, 15 Apr 2020 15:08:28 +0200 Subject: [PATCH] fix #183 : refresh cursor position on activity --- src/js/easymde.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/js/easymde.js b/src/js/easymde.js index d64a52f..d537a49 100644 --- a/src/js/easymde.js +++ b/src/js/easymde.js @@ -2372,11 +2372,12 @@ EasyMDE.prototype.createStatusbar = function (status) { // Set up the built-in items var items = []; - var i, onUpdate, defaultValue; + var i, onUpdate, onActivity, defaultValue; for (i = 0; i < status.length; i++) { // Reset some values onUpdate = undefined; + onActivity = undefined; defaultValue = undefined; @@ -2386,6 +2387,7 @@ EasyMDE.prototype.createStatusbar = function (status) { className: status[i].className, defaultValue: status[i].defaultValue, onUpdate: status[i].onUpdate, + onActivity: status[i].onActivity, }); } else { var name = status[i]; @@ -2408,7 +2410,7 @@ EasyMDE.prototype.createStatusbar = function (status) { defaultValue = function (el) { el.innerHTML = '0:0'; }; - onUpdate = function (el) { + onActivity = function (el) { var pos = cm.getCursor(); el.innerHTML = pos.line + ':' + pos.ch; }; @@ -2428,6 +2430,7 @@ EasyMDE.prototype.createStatusbar = function (status) { className: name, defaultValue: defaultValue, onUpdate: onUpdate, + onActivity: onActivity, }); } } @@ -2464,6 +2467,14 @@ EasyMDE.prototype.createStatusbar = function (status) { }; }(el, item))); } + if (typeof item.onActivity === 'function') { + // Create a closure around the span of the current action, then execute the onActivity handler + this.codemirror.on('cursorActivity', (function (el, item) { + return function () { + item.onActivity(el); + }; + }(el, item))); + } // Append the item to the status bar