Skip to content

Commit 9338989

Browse files
committed
chore: editor.clearAllMarks api will now take optional linenumbers to clear only
1 parent 0919336 commit 9338989

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/editor/Editor.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,13 +1491,34 @@ define(function (require, exports, module) {
14911491
};
14921492

14931493
/**
1494-
* Clears all mark of the given type. If nothing is given, clears all marks(Don't use this API without types!).
1494+
* Clears all marks of the given type. If a lineNumbers array is given, only clears marks on those lines.
1495+
* If no markType or lineNumbers are given, clears all marks (use cautiously).
14951496
* @param {string} [markType] - Optional, if given will only delete marks of that type. Else delete everything.
1497+
* @param {number[]} [lineNumbers] - Optional, array of line numbers where marks should be cleared.
14961498
*/
1497-
Editor.prototype.clearAllMarks = function (markType) {
1499+
Editor.prototype.clearAllMarks = function (markType, lineNumbers) {
14981500
const self = this;
1501+
14991502
self._codeMirror.operation(function () {
15001503
let marks = self.getAllMarks(markType);
1504+
1505+
if (lineNumbers && Array.isArray(lineNumbers)) {
1506+
// Filter marks to only those within the specified line numbers
1507+
marks = marks.filter(function (mark) {
1508+
const range = mark.find(); // Get the range of the mark
1509+
if (!range) {
1510+
return false;
1511+
}
1512+
1513+
const startLine = range.from.line;
1514+
const endLine = range.to.line;
1515+
1516+
// Check if the mark overlaps with any of the specified lines
1517+
return lineNumbers.some(line => line >= startLine && line <= endLine);
1518+
});
1519+
}
1520+
1521+
// Clear the filtered marks
15011522
for (let mark of marks) {
15021523
mark.clear();
15031524
}

0 commit comments

Comments
 (0)