"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ErrorHighlight = exports.error_highlight_extension = void 0;
const state_1 = require("@codemirror/state");
const view_1 = require("@codemirror/view");
// code mirror effect that you will use to define the effect you want (the decoration)
const addErrorEffect = state_1.StateEffect.define();
const removeErrorEffect = state_1.StateEffect.define();
// define a new field that will be attached to your view state as an extension, update will be called at each editor's change
exports.error_highlight_extension = state_1.StateField.define({
    create() { return view_1.Decoration.none; },
    update(value, transaction) {
        value = value.map(transaction.changes);
        for (let effect of transaction.effects) {
            if (effect.is(addErrorEffect))
                value = value.update({ add: effect.value, sort: true });
            else if (effect.is(removeErrorEffect))
                value = value.update({ filter: effect.value });
        }
        return value;
    },
    provide: f => view_1.EditorView.decorations.from(f),
});
// this is your decoration where you can define the change you want : a css class or directly css attributes
const error_decoration = view_1.Decoration.mark({
    inclusive: true,
    attributes: { style: "/* background-color: #b7c1e8; border: red 1px solid; */ color: red; font-weight: bold; " },
    tagName: "span",
    // class: 'red_back'
});
function highlightError(editor, from, to) {
    // this is where the change takes effect by the dispatch. The of method instanciate the effect. You need to put this code where you want the change to take place
    editor.dispatch({
        effects: addErrorEffect.of([error_decoration.range(from, to)])
    });
}
function removeErrors(editor) {
    editor.dispatch({
        effects: removeErrorEffect.of(() => false)
    });
}
class ErrorHighlight {
    constructor(tc) {
        this.parameterChangeListener = undefined;
        this.tc = tc;
    }
    setError(i0, i1) {
        this.clearError();
        if (i0 === i1)
            i1++;
        highlightError(this.tc, i0, i1);
    }
    clearError() {
        removeErrors(this.tc);
    }
}
exports.ErrorHighlight = ErrorHighlight;
//# sourceMappingURL=ErrorHighlight.js.map