Skip to content

Commit

Permalink
Use proper map for line mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincarrogan committed Jan 19, 2025
1 parent 0f857b8 commit 52c1009
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Editor {

constructor($el) {
this.setup($el);
this.highlightMap = {};
this.highlightMap = new Map();
}

setup($el) {
Expand All @@ -32,7 +32,7 @@ class Editor {
}

highlightLine(lineNumber, style) {
if (this.highlightMap[lineNumber]) {
if (this.highlightMap.has(lineNumber)) {
this.removeHighlight(lineNumber);
}

Expand All @@ -45,20 +45,20 @@ class Editor {
const lines = this.editor.wrapper.children;
lines[lineNumber].prepend(element);

this.highlightMap[lineNumber] = element;
this.highlightMap.set(lineNumber, element);
}

removeHighlight(lineNumber) {
const element = this.highlightMap[lineNumber];
const element = this.highlightMap.get(lineNumber);
element.remove();
delete this.highlightMap[lineNumber];
this.highlightMap.delete(lineNumber);
}

clearHighlights() {
for (const element of Object.values(this.highlightMap)) {
element.remove();
}
this.highlightMap = {};
this.highlightMap.clear();
}

getValue() {
Expand Down

0 comments on commit 52c1009

Please sign in to comment.