Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix code highlighting bug #1600

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions web/src/components/pair/PairCodeMatchEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const emit = defineEmits(["update:selectedMatch", "update:hoveringMatch"]);
const colors = {
match: "rgba(60, 115, 168, 0.2)",
matchHovering: "rgba(60, 115, 168, 0.3)",
matchSelected: "rgba(26, 188, 156, 0.3)",
matchSelected: "rgba(26, 188, 156, 0.5)",
};

// File to display
Expand Down Expand Up @@ -180,6 +180,15 @@ const initializeSelections = (): void => {
}
};

const areMatchesEqual = (match1: Fragment | null, match2: Fragment | null) => {
if (!match1 || !match2) return false;

return match1.left.startCol === match2.left.startCol &&
match1.left.endCol === match2.left.endCol &&
match1.right.startCol === match2.right.startCol &&
match1.right.endCol === match2.right.endCol;
};

// Initialize the editor decorations
const initializeDecorations = (): void => {
// Convert the selections into Monaco decorations.
Expand All @@ -189,12 +198,13 @@ const initializeDecorations = (): void => {
const match = selection.match;

let classname = "highlight-match";
if (match === selectedMatch.value) classname += " highlight-match--selected";
else if (match === hoveringMatch.value) classname += " highlight-match--hovering";
if (areMatchesEqual(match, selectedMatch?.value)) classname += " highlight-match--selected";
else if (areMatchesEqual(match, hoveringMatch?.value)) classname += " highlight-match--hovering";


let color = colors.match;
if (match === selectedMatch.value) color = colors.matchSelected;
else if (match === hoveringMatch.value) color = colors.matchHovering;
if (areMatchesEqual(match, selectedMatch?.value)) color = colors.matchSelected;
else if (areMatchesEqual(match, hoveringMatch?.value)) color = colors.matchHovering;

return {
range: selection.range,
Expand Down