Skip to content

Commit 97a9bef

Browse files
authored
Merge pull request #1600 from mikaelGusse/main
Fix code highlighting bug
2 parents 8933ec7 + 7e388ab commit 97a9bef

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

web/src/components/pair/PairCodeMatchEditor.vue

+15-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const emit = defineEmits(["update:selectedMatch", "update:hoveringMatch"]);
4343
const colors = {
4444
match: "rgba(60, 115, 168, 0.2)",
4545
matchHovering: "rgba(60, 115, 168, 0.3)",
46-
matchSelected: "rgba(26, 188, 156, 0.3)",
46+
matchSelected: "rgba(26, 188, 156, 0.5)",
4747
};
4848
4949
// File to display
@@ -180,6 +180,15 @@ const initializeSelections = (): void => {
180180
}
181181
};
182182
183+
const areMatchesEqual = (match1: Fragment | null, match2: Fragment | null) => {
184+
if (!match1 || !match2) return false;
185+
186+
return match1.left.startCol === match2.left.startCol &&
187+
match1.left.endCol === match2.left.endCol &&
188+
match1.right.startCol === match2.right.startCol &&
189+
match1.right.endCol === match2.right.endCol;
190+
};
191+
183192
// Initialize the editor decorations
184193
const initializeDecorations = (): void => {
185194
// Convert the selections into Monaco decorations.
@@ -189,12 +198,13 @@ const initializeDecorations = (): void => {
189198
const match = selection.match;
190199
191200
let classname = "highlight-match";
192-
if (match === selectedMatch.value) classname += " highlight-match--selected";
193-
else if (match === hoveringMatch.value) classname += " highlight-match--hovering";
201+
if (areMatchesEqual(match, selectedMatch?.value)) classname += " highlight-match--selected";
202+
else if (areMatchesEqual(match, hoveringMatch?.value)) classname += " highlight-match--hovering";
203+
194204
195205
let color = colors.match;
196-
if (match === selectedMatch.value) color = colors.matchSelected;
197-
else if (match === hoveringMatch.value) color = colors.matchHovering;
206+
if (areMatchesEqual(match, selectedMatch?.value)) color = colors.matchSelected;
207+
else if (areMatchesEqual(match, hoveringMatch?.value)) color = colors.matchHovering;
198208
199209
return {
200210
range: selection.range,

0 commit comments

Comments
 (0)