Skip to content

Commit b930ef0

Browse files
committed
chore: performance improvmenet for clear all editor marks
1 parent 5accc1a commit b930ef0

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

src/editor/Editor.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,10 +1313,24 @@ define(function (require, exports, module) {
13131313
* @param {string} [markType] - Optional, if given will only delete marks of that type. Else delete everything.
13141314
*/
13151315
Editor.prototype.clearAllMarks = function (markType) {
1316-
let marks = this.getAllMarks(markType);
1317-
for(let mark of marks){
1318-
mark.clear();
1319-
}
1316+
const self = this;
1317+
self._codeMirror.operation(function () {
1318+
let marks = self.getAllMarks(markType);
1319+
for(let mark of marks){
1320+
mark.clear();
1321+
}
1322+
});
1323+
};
1324+
1325+
/**
1326+
* Checks if two positions in the editor are the same.
1327+
*
1328+
* @param {{line: number, ch: number}} position1 - cursor position
1329+
* @param {{line: number, ch: number}} position2 - cursor position
1330+
* @returns {boolean} True if both positions are the same, false otherwise.
1331+
*/
1332+
Editor.prototype.isSamePosition = function (position1, position2){
1333+
return position1.line === position2.line && position1.ch === position2.ch;
13201334
};
13211335

13221336
/**

src/language/CodeInspection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ define(function (require, exports, module) {
558558
markOptions.metadata = fixID;
559559
error.fix.id = fixID;
560560
}
561-
if(error.endPos){
561+
if(error.endPos && !editor.isSamePosition(error.pos, error.endPos)) {
562562
mark = editor.markText(CODE_MARK_TYPE_INSPECTOR, error.pos, error.endPos, markOptions);
563563
} else {
564564
mark = editor.markToken(CODE_MARK_TYPE_INSPECTOR, error.pos, markOptions);

0 commit comments

Comments
 (0)