2
0
mirror of https://github.com/Ionaru/easy-markdown-editor synced 2025-07-02 15:44:28 -06:00

fix #183 : refresh cursor position on activity

This commit is contained in:
firm1 2020-04-15 15:08:28 +02:00
parent 228fe91a72
commit 24d4cc87af

View File

@ -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