"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PairingCharactersExtension = void 0;
const state_1 = require("@codemirror/state");
const view_1 = require("@codemirror/view");
const PAIRING_CHARS = new Map([
    ['(', ')'],
    ['{', '}'],
    ['[', ']'],
    ['<', '>'],
    ['*', '*'],
    ['~', '~'],
    ['"', '"'],
    ["'", "'"],
    ['`', '`'],
]);
exports.PairingCharactersExtension = view_1.EditorView.inputHandler.of((view, _1, _2, text) => {
    if (!PAIRING_CHARS.has(text))
        return false;
    const tr = view.state.changeByRange((range) => {
        const changes = [{ from: range.from, insert: text }];
        if (!range.empty)
            changes.push({ from: range.to, insert: PAIRING_CHARS.get(text) });
        const changeSet = state_1.ChangeSet.of(changes, view.state.doc.length);
        return { changes: changeSet, range: range.map(changeSet, range.empty ? 1 : 0) };
    });
    view.dispatch(tr, { scrollIntoView: true });
    return true;
});
//# sourceMappingURL=pairing-chars.js.map
