mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-11 21:58:31 +00:00
- dedupe flash / highlighting logic - codemirror logic now lives only in codemirror package - remove old highlighting logic - use codemirror package in react package - cleanup CodeMirror6.jsx - pull setMiniLocations into useHighlighting - migrate MiniRepl, nano-repl + Repl to new highlighting
36 lines
1008 B
JavaScript
36 lines
1008 B
JavaScript
import { StateEffect, StateField } from '@codemirror/state';
|
|
import { Decoration, EditorView } from '@codemirror/view';
|
|
|
|
export const setFlash = StateEffect.define();
|
|
export const flashField = StateField.define({
|
|
create() {
|
|
return Decoration.none;
|
|
},
|
|
update(flash, tr) {
|
|
try {
|
|
for (let e of tr.effects) {
|
|
if (e.is(setFlash)) {
|
|
if (e.value && tr.newDoc.length > 0) {
|
|
const mark = Decoration.mark({ attributes: { style: `background-color: #FFCA2880` } });
|
|
flash = Decoration.set([mark.range(0, tr.newDoc.length)]);
|
|
} else {
|
|
flash = Decoration.set([]);
|
|
}
|
|
}
|
|
}
|
|
return flash;
|
|
} catch (err) {
|
|
console.warn('flash error', err);
|
|
return flash;
|
|
}
|
|
},
|
|
provide: (f) => EditorView.decorations.from(f),
|
|
});
|
|
|
|
export const flash = (view, ms = 200) => {
|
|
view.dispatch({ effects: setFlash.of(true) });
|
|
setTimeout(() => {
|
|
view.dispatch({ effects: setFlash.of(false) });
|
|
}, ms);
|
|
};
|