Skip to content

Commit

Permalink
fix: maybe fixes cmd+click, remove all underlines (marimo-team#1463)
Browse files Browse the repository at this point in the history
* remove all underlines

* add ctrl
  • Loading branch information
mscolnick authored May 23, 2024
1 parent a0fd9a0 commit 949a5f7
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions frontend/src/core/codemirror/go-to-definition/underline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const underlineDecoration = Decoration.mark({ class: "underline" });

// State Effects
const addUnderline = StateEffect.define<{ from: number; to: number }>();
const removeUnderline = StateEffect.define<{ from: number; to: number }>();
const removeUnderlines = StateEffect.define();

// Underline Field
export const underlineField = StateField.define<DecorationSet>({
Expand All @@ -29,11 +29,8 @@ export const underlineField = StateField.define<DecorationSet>({
newUnderlines = underlines.update({
add: [underlineDecoration.range(effect.value.from, effect.value.to)],
});
} else if (effect.is(removeUnderline)) {
newUnderlines = underlines.update({
filter: (from, to) =>
from !== effect.value.from || to !== effect.value.to,
});
} else if (effect.is(removeUnderlines)) {
newUnderlines = Decoration.none;
}
}
return newUnderlines;
Expand Down Expand Up @@ -111,7 +108,7 @@ class MetaUnderlineVariablePlugin {
};

private keydown = (event: KeyboardEvent) => {
if (event.key === "Meta") {
if (event.key === "Meta" || event.key === "Ctrl") {
this.commandKey = true;
}
};
Expand All @@ -136,15 +133,15 @@ class MetaUnderlineVariablePlugin {
};

private keyup = (event: KeyboardEvent) => {
if (event.key === "Meta") {
if (event.key === "Meta" || event.key === "Ctrl") {
this.commandKey = false;
this.clearUnderline();
}
};

private clearUnderline() {
if (this.hoveredRange) {
this.view.dispatch({ effects: removeUnderline.of(this.hoveredRange) });
this.view.dispatch({ effects: removeUnderlines.of(null) });
this.hoveredRange = null;
}
}
Expand Down

0 comments on commit 949a5f7

Please sign in to comment.