Skip to content

Commit

Permalink
chore: editor.clearAllMarks api will now take optional linenumbers to…
Browse files Browse the repository at this point in the history
… clear only
  • Loading branch information
abose committed Dec 10, 2024
1 parent 0919336 commit 9338989
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1491,13 +1491,34 @@ define(function (require, exports, module) {
};

/**
* Clears all mark of the given type. If nothing is given, clears all marks(Don't use this API without types!).
* Clears all marks of the given type. If a lineNumbers array is given, only clears marks on those lines.
* If no markType or lineNumbers are given, clears all marks (use cautiously).
* @param {string} [markType] - Optional, if given will only delete marks of that type. Else delete everything.
* @param {number[]} [lineNumbers] - Optional, array of line numbers where marks should be cleared.
*/
Editor.prototype.clearAllMarks = function (markType) {
Editor.prototype.clearAllMarks = function (markType, lineNumbers) {
const self = this;

self._codeMirror.operation(function () {
let marks = self.getAllMarks(markType);

if (lineNumbers && Array.isArray(lineNumbers)) {
// Filter marks to only those within the specified line numbers
marks = marks.filter(function (mark) {
const range = mark.find(); // Get the range of the mark
if (!range) {
return false;
}

const startLine = range.from.line;
const endLine = range.to.line;

// Check if the mark overlaps with any of the specified lines
return lineNumbers.some(line => line >= startLine && line <= endLine);
});
}

// Clear the filtered marks
for (let mark of marks) {
mark.clear();
}
Expand Down

0 comments on commit 9338989

Please sign in to comment.