Skip to content

Commit

Permalink
fix: stuck flashes (#308)
Browse files Browse the repository at this point in the history
removed the timeout clear, because it would overwrite currently active
timeouts, leading to stuck flash highlights. without clearing, the worst
thing that can happen is that you evaluate twice within 150 ms and get a
slightly shorter flash

fixes #296
  • Loading branch information
munshkr authored Dec 23, 2024
2 parents 39a05e5 + 41c6da8 commit 1b53ab6
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions packages/cm-eval/lib/flashField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { StateField, StateEffect } from "@codemirror/state";

type FlashRange = [number, number];

let timeoutId: any;

export const setFlash = StateEffect.define<FlashRange | null>();

const defaultStyle = {
Expand All @@ -23,9 +21,8 @@ export const flash = (
timeout: number = 150
) => {
if (from === null || to === null) return;
clearTimeout(timeoutId);
view.dispatch({ effects: setFlash.of([from, to]) });
timeoutId = setTimeout(() => {
setTimeout(() => {
view.dispatch({ effects: setFlash.of(null) });
}, timeout);
};
Expand Down

0 comments on commit 1b53ab6

Please sign in to comment.