2
0
mirror of https://github.com/Ionaru/easy-markdown-editor synced 2025-07-21 08:54:28 -06:00

Merge pull request #184 from firm1/fix_183

Fix refresh display cursor position
This commit is contained in:
Jeroen Akkerman 2020-04-20 15:12:49 +02:00 committed by GitHub
commit b1d29c491f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View File

@ -4,7 +4,10 @@ All notable changes to easymde will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
<!--## [Unreleased]--> ## [Unreleased]
### Fixed
- Fix cursor displayed position on activity ([#183]).
## [2.10.1] - 2020-04-06 ## [2.10.1] - 2020-04-06
### Fixed ### Fixed
- Typescript error when entering certain strings for toolbar buttons ([#178]). - Typescript error when entering certain strings for toolbar buttons ([#178]).

View File

@ -2372,11 +2372,12 @@ EasyMDE.prototype.createStatusbar = function (status) {
// Set up the built-in items // Set up the built-in items
var items = []; var items = [];
var i, onUpdate, defaultValue; var i, onUpdate, onActivity, defaultValue;
for (i = 0; i < status.length; i++) { for (i = 0; i < status.length; i++) {
// Reset some values // Reset some values
onUpdate = undefined; onUpdate = undefined;
onActivity = undefined;
defaultValue = undefined; defaultValue = undefined;
@ -2386,6 +2387,7 @@ EasyMDE.prototype.createStatusbar = function (status) {
className: status[i].className, className: status[i].className,
defaultValue: status[i].defaultValue, defaultValue: status[i].defaultValue,
onUpdate: status[i].onUpdate, onUpdate: status[i].onUpdate,
onActivity: status[i].onActivity,
}); });
} else { } else {
var name = status[i]; var name = status[i];
@ -2408,7 +2410,7 @@ EasyMDE.prototype.createStatusbar = function (status) {
defaultValue = function (el) { defaultValue = function (el) {
el.innerHTML = '0:0'; el.innerHTML = '0:0';
}; };
onUpdate = function (el) { onActivity = function (el) {
var pos = cm.getCursor(); var pos = cm.getCursor();
el.innerHTML = pos.line + ':' + pos.ch; el.innerHTML = pos.line + ':' + pos.ch;
}; };
@ -2428,6 +2430,7 @@ EasyMDE.prototype.createStatusbar = function (status) {
className: name, className: name,
defaultValue: defaultValue, defaultValue: defaultValue,
onUpdate: onUpdate, onUpdate: onUpdate,
onActivity: onActivity,
}); });
} }
} }
@ -2464,6 +2467,14 @@ EasyMDE.prototype.createStatusbar = function (status) {
}; };
}(el, item))); }(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 // Append the item to the status bar