UNPKG

@theia/monaco

Version:
74 lines 3.02 kB
"use strict"; // ***************************************************************************** // Copyright (C) 2020 TypeFox and others. // // This program and the accompanying materials are made available under the // terms of the Eclipse Public License v. 2.0 which is available at // http://www.eclipse.org/legal/epl-2.0. // // This Source Code may also be made available under the following Secondary // Licenses when the conditions for such availability set forth in the Eclipse // Public License v. 2.0 are satisfied: GNU General Public License, version 2 // with the GNU Classpath Exception which is available at // https://www.gnu.org/software/classpath/license.html. // // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 // ***************************************************************************** Object.defineProperty(exports, "__esModule", { value: true }); exports.MonacoToProtocolConverter = exports.MonacoRangeReplace = void 0; const tslib_1 = require("tslib"); const inversify_1 = require("@theia/core/shared/inversify"); const monaco = require("@theia/monaco-editor-core"); ; var MonacoRangeReplace; (function (MonacoRangeReplace) { function is(v) { return v.insert !== undefined; } MonacoRangeReplace.is = is; })(MonacoRangeReplace || (exports.MonacoRangeReplace = MonacoRangeReplace = {})); let MonacoToProtocolConverter = class MonacoToProtocolConverter { asPosition(lineNumber, column) { const line = typeof lineNumber !== 'number' ? undefined : lineNumber - 1; const character = typeof column !== 'number' ? undefined : column - 1; return { line, character }; } asRange(range) { if (range === undefined) { return undefined; } if (MonacoRangeReplace.is(range)) { return this.asRange(range.insert); } else { const start = this.asPosition(range.startLineNumber, range.startColumn); const end = this.asPosition(range.endLineNumber, range.endColumn); return { start, end }; } } asSelection(selection) { if (!selection) { return { start: { line: 0, character: 0 }, end: { line: 0, character: 0 }, direction: 'ltr' }; } const start = this.asPosition(selection.selectionStartLineNumber, selection.selectionStartColumn); const end = this.asPosition(selection.positionLineNumber, selection.positionColumn); return { start, end, direction: selection.getDirection() === monaco.SelectionDirection.LTR ? 'ltr' : 'rtl' }; } }; exports.MonacoToProtocolConverter = MonacoToProtocolConverter; exports.MonacoToProtocolConverter = MonacoToProtocolConverter = tslib_1.__decorate([ (0, inversify_1.injectable)() ], MonacoToProtocolConverter); //# sourceMappingURL=monaco-to-protocol-converter.js.map