yanzi-monaco-editor
Version:
这是一个基于微软的monaco和vue封装的一个代码编辑器,浏览器可运行。主要功能有:html、javascript、css代码编辑,高亮显示,语法错误提示等,可以帮您的项目很快的拥有一个web端的代码编辑器
1,047 lines (962 loc) • 8.68 MB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("vue"));
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["yanziMonacoEditor"] = factory(require("vue"));
else
root["yanziMonacoEditor"] = factory(root["Vue"]);
})((typeof self !== 'undefined' ? self : this), function(__WEBPACK_EXTERNAL_MODULE__8bbf__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // install a JSONP callback for chunk loading
/******/ function webpackJsonpCallback(data) {
/******/ var chunkIds = data[0];
/******/ var moreModules = data[1];
/******/
/******/
/******/ // add "moreModules" to the modules object,
/******/ // then flag all "chunkIds" as loaded and fire callback
/******/ var moduleId, chunkId, i = 0, resolves = [];
/******/ for(;i < chunkIds.length; i++) {
/******/ chunkId = chunkIds[i];
/******/ if(Object.prototype.hasOwnProperty.call(installedChunks, chunkId) && installedChunks[chunkId]) {
/******/ resolves.push(installedChunks[chunkId][0]);
/******/ }
/******/ installedChunks[chunkId] = 0;
/******/ }
/******/ for(moduleId in moreModules) {
/******/ if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {
/******/ modules[moduleId] = moreModules[moduleId];
/******/ }
/******/ }
/******/ if(parentJsonpFunction) parentJsonpFunction(data);
/******/
/******/ while(resolves.length) {
/******/ resolves.shift()();
/******/ }
/******/
/******/ };
/******/
/******/
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // object to store loaded and loading chunks
/******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched
/******/ // Promise = chunk loading, 0 = chunk loaded
/******/ var installedChunks = {
/******/ 2: 0
/******/ };
/******/
/******/
/******/
/******/ // script path function
/******/ function jsonpScriptSrc(chunkId) {
/******/ return __webpack_require__.p + "yanziMonacoEditor.umd." + ({}[chunkId]||chunkId) + ".js"
/******/ }
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/ // This file contains only the entry chunk.
/******/ // The chunk loading function for additional chunks
/******/ __webpack_require__.e = function requireEnsure(chunkId) {
/******/ var promises = [];
/******/
/******/
/******/ // JSONP chunk loading for javascript
/******/
/******/ var installedChunkData = installedChunks[chunkId];
/******/ if(installedChunkData !== 0) { // 0 means "already installed".
/******/
/******/ // a Promise means "currently loading".
/******/ if(installedChunkData) {
/******/ promises.push(installedChunkData[2]);
/******/ } else {
/******/ // setup Promise in chunk cache
/******/ var promise = new Promise(function(resolve, reject) {
/******/ installedChunkData = installedChunks[chunkId] = [resolve, reject];
/******/ });
/******/ promises.push(installedChunkData[2] = promise);
/******/
/******/ // start chunk loading
/******/ var script = document.createElement('script');
/******/ var onScriptComplete;
/******/
/******/ script.charset = 'utf-8';
/******/ script.timeout = 120;
/******/ if (__webpack_require__.nc) {
/******/ script.setAttribute("nonce", __webpack_require__.nc);
/******/ }
/******/ script.src = jsonpScriptSrc(chunkId);
/******/
/******/ // create error before stack unwound to get useful stacktrace later
/******/ var error = new Error();
/******/ onScriptComplete = function (event) {
/******/ // avoid mem leaks in IE.
/******/ script.onerror = script.onload = null;
/******/ clearTimeout(timeout);
/******/ var chunk = installedChunks[chunkId];
/******/ if(chunk !== 0) {
/******/ if(chunk) {
/******/ var errorType = event && (event.type === 'load' ? 'missing' : event.type);
/******/ var realSrc = event && event.target && event.target.src;
/******/ error.message = 'Loading chunk ' + chunkId + ' failed.\n(' + errorType + ': ' + realSrc + ')';
/******/ error.name = 'ChunkLoadError';
/******/ error.type = errorType;
/******/ error.request = realSrc;
/******/ chunk[1](error);
/******/ }
/******/ installedChunks[chunkId] = undefined;
/******/ }
/******/ };
/******/ var timeout = setTimeout(function(){
/******/ onScriptComplete({ type: 'timeout', target: script });
/******/ }, 120000);
/******/ script.onerror = script.onload = onScriptComplete;
/******/ document.head.appendChild(script);
/******/ }
/******/ }
/******/ return Promise.all(promises);
/******/ };
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // on error function for async loading
/******/ __webpack_require__.oe = function(err) { console.error(err); throw err; };
/******/
/******/ var jsonpArray = (typeof self !== 'undefined' ? self : this)["webpackJsonpyanziMonacoEditor"] = (typeof self !== 'undefined' ? self : this)["webpackJsonpyanziMonacoEditor"] || [];
/******/ var oldJsonpFunction = jsonpArray.push.bind(jsonpArray);
/******/ jsonpArray.push = webpackJsonpCallback;
/******/ jsonpArray = jsonpArray.slice();
/******/ for(var i = 0; i < jsonpArray.length; i++) webpackJsonpCallback(jsonpArray[i]);
/******/ var parentJsonpFunction = oldJsonpFunction;
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = "3e6d");
/******/ })
/************************************************************************/
/******/ ({
/***/ "012d":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return _util; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return IInstantiationService; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "c", function() { return createDecorator; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "d", function() { return optional; });
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
// ------ internal util
var _util;
(function (_util) {
_util.serviceIds = new Map();
_util.DI_TARGET = '$di$target';
_util.DI_DEPENDENCIES = '$di$dependencies';
function getServiceDependencies(ctor) {
return ctor[_util.DI_DEPENDENCIES] || [];
}
_util.getServiceDependencies = getServiceDependencies;
})(_util || (_util = {}));
const IInstantiationService = createDecorator('instantiationService');
function storeServiceDependency(id, target, index, optional) {
if (target[_util.DI_TARGET] === target) {
target[_util.DI_DEPENDENCIES].push({ id, index, optional });
}
else {
target[_util.DI_DEPENDENCIES] = [{ id, index, optional }];
target[_util.DI_TARGET] = target;
}
}
/**
* The *only* valid way to create a {{ServiceIdentifier}}.
*/
function createDecorator(serviceId) {
if (_util.serviceIds.has(serviceId)) {
return _util.serviceIds.get(serviceId);
}
const id = function (target, key, index) {
if (arguments.length !== 3) {
throw new Error('@IServiceName-decorator can only be used to decorate a parameter');
}
storeServiceDependency(id, target, index, false);
};
id.toString = () => serviceId;
_util.serviceIds.set(serviceId, id);
return id;
}
/**
* Mark a service dependency as optional.
*/
function optional(serviceIdentifier) {
return function (target, key, index) {
if (arguments.length !== 3) {
throw new Error('@optional-decorator can only be used to decorate a parameter');
}
storeServiceDependency(serviceIdentifier, target, index, true);
};
}
/***/ }),
/***/ "017f":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return createScopedLineTokens; });
/* unused harmony export ScopedLineTokens */
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return ignoreBracketsInToken; });
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
function createScopedLineTokens(context, offset) {
let tokenCount = context.getCount();
let tokenIndex = context.findTokenIndexAtOffset(offset);
let desiredLanguageId = context.getLanguageId(tokenIndex);
let lastTokenIndex = tokenIndex;
while (lastTokenIndex + 1 < tokenCount && context.getLanguageId(lastTokenIndex + 1) === desiredLanguageId) {
lastTokenIndex++;
}
let firstTokenIndex = tokenIndex;
while (firstTokenIndex > 0 && context.getLanguageId(firstTokenIndex - 1) === desiredLanguageId) {
firstTokenIndex--;
}
return new ScopedLineTokens(context, desiredLanguageId, firstTokenIndex, lastTokenIndex + 1, context.getStartOffset(firstTokenIndex), context.getEndOffset(lastTokenIndex));
}
class ScopedLineTokens {
constructor(actual, languageId, firstTokenIndex, lastTokenIndex, firstCharOffset, lastCharOffset) {
this._actual = actual;
this.languageId = languageId;
this._firstTokenIndex = firstTokenIndex;
this._lastTokenIndex = lastTokenIndex;
this.firstCharOffset = firstCharOffset;
this._lastCharOffset = lastCharOffset;
}
getLineContent() {
const actualLineContent = this._actual.getLineContent();
return actualLineContent.substring(this.firstCharOffset, this._lastCharOffset);
}
getActualLineContentBefore(offset) {
const actualLineContent = this._actual.getLineContent();
return actualLineContent.substring(0, this.firstCharOffset + offset);
}
getTokenCount() {
return this._lastTokenIndex - this._firstTokenIndex;
}
findTokenIndexAtOffset(offset) {
return this._actual.findTokenIndexAtOffset(offset + this.firstCharOffset) - this._firstTokenIndex;
}
getStandardTokenType(tokenIndex) {
return this._actual.getStandardTokenType(tokenIndex + this._firstTokenIndex);
}
}
function ignoreBracketsInToken(standardTokenType) {
return (standardTokenType & 7 /* value */) !== 0;
}
/***/ }),
/***/ "0248":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _base_common_arrays_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("e847");
/* harmony import */ var _base_common_cancellation_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("cba3");
/* harmony import */ var _base_common_keyCodes_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("4a66");
/* harmony import */ var _base_common_lifecycle_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("e3ad");
/* harmony import */ var _browser_editorExtensions_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("3658");
/* harmony import */ var _browser_services_codeEditorService_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__("63d8");
/* harmony import */ var _common_core_characterClassifier_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__("b33f");
/* harmony import */ var _common_core_range_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__("ea0d");
/* harmony import */ var _common_editorContextKeys_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__("db1e");
/* harmony import */ var _common_modes_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__("4597");
/* harmony import */ var _common_services_editorWorkerService_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__("35fc");
/* harmony import */ var _format_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__("e624");
/* harmony import */ var _formattingEdit_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__("217b");
/* harmony import */ var _nls_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__("484b");
/* harmony import */ var _platform_commands_common_commands_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__("20cd");
/* harmony import */ var _platform_contextkey_common_contextkey_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__("4f24");
/* harmony import */ var _platform_instantiation_common_instantiation_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__("012d");
/* harmony import */ var _base_common_errors_js__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__("80e8");
/* harmony import */ var _platform_progress_common_progress_js__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__("e0ca");
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __param = (undefined && undefined.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
let FormatOnType = class FormatOnType {
constructor(editor, _workerService) {
this._workerService = _workerService;
this._callOnDispose = new _base_common_lifecycle_js__WEBPACK_IMPORTED_MODULE_3__[/* DisposableStore */ "b"]();
this._callOnModel = new _base_common_lifecycle_js__WEBPACK_IMPORTED_MODULE_3__[/* DisposableStore */ "b"]();
this._editor = editor;
this._callOnDispose.add(editor.onDidChangeConfiguration(() => this._update()));
this._callOnDispose.add(editor.onDidChangeModel(() => this._update()));
this._callOnDispose.add(editor.onDidChangeModelLanguage(() => this._update()));
this._callOnDispose.add(_common_modes_js__WEBPACK_IMPORTED_MODULE_9__[/* OnTypeFormattingEditProviderRegistry */ "v"].onDidChange(this._update, this));
}
dispose() {
this._callOnDispose.dispose();
this._callOnModel.dispose();
}
_update() {
// clean up
this._callOnModel.clear();
// we are disabled
if (!this._editor.getOption(43 /* formatOnType */)) {
return;
}
// no model
if (!this._editor.hasModel()) {
return;
}
const model = this._editor.getModel();
// no support
const [support] = _common_modes_js__WEBPACK_IMPORTED_MODULE_9__[/* OnTypeFormattingEditProviderRegistry */ "v"].ordered(model);
if (!support || !support.autoFormatTriggerCharacters) {
return;
}
// register typing listeners that will trigger the format
let triggerChars = new _common_core_characterClassifier_js__WEBPACK_IMPORTED_MODULE_6__[/* CharacterSet */ "b"]();
for (let ch of support.autoFormatTriggerCharacters) {
triggerChars.add(ch.charCodeAt(0));
}
this._callOnModel.add(this._editor.onDidType((text) => {
let lastCharCode = text.charCodeAt(text.length - 1);
if (triggerChars.has(lastCharCode)) {
this._trigger(String.fromCharCode(lastCharCode));
}
}));
}
_trigger(ch) {
if (!this._editor.hasModel()) {
return;
}
if (this._editor.getSelections().length > 1) {
return;
}
const model = this._editor.getModel();
const position = this._editor.getPosition();
let canceled = false;
// install a listener that checks if edits happens before the
// position on which we format right now. If so, we won't
// apply the format edits
const unbind = this._editor.onDidChangeModelContent((e) => {
if (e.isFlush) {
// a model.setValue() was called
// cancel only once
canceled = true;
unbind.dispose();
return;
}
for (let i = 0, len = e.changes.length; i < len; i++) {
const change = e.changes[i];
if (change.range.endLineNumber <= position.lineNumber) {
// cancel only once
canceled = true;
unbind.dispose();
return;
}
}
});
Object(_format_js__WEBPACK_IMPORTED_MODULE_11__[/* getOnTypeFormattingEdits */ "e"])(this._workerService, model, position, ch, model.getFormattingOptions()).then(edits => {
unbind.dispose();
if (canceled) {
return;
}
if (Object(_base_common_arrays_js__WEBPACK_IMPORTED_MODULE_0__[/* isNonEmptyArray */ "m"])(edits)) {
_formattingEdit_js__WEBPACK_IMPORTED_MODULE_12__[/* FormattingEdit */ "a"].execute(this._editor, edits, true);
Object(_format_js__WEBPACK_IMPORTED_MODULE_11__[/* alertFormattingEdits */ "b"])(edits);
}
}, (err) => {
unbind.dispose();
throw err;
});
}
};
FormatOnType.ID = 'editor.contrib.autoFormat';
FormatOnType = __decorate([
__param(1, _common_services_editorWorkerService_js__WEBPACK_IMPORTED_MODULE_10__[/* IEditorWorkerService */ "a"])
], FormatOnType);
let FormatOnPaste = class FormatOnPaste {
constructor(editor, _instantiationService) {
this.editor = editor;
this._instantiationService = _instantiationService;
this._callOnDispose = new _base_common_lifecycle_js__WEBPACK_IMPORTED_MODULE_3__[/* DisposableStore */ "b"]();
this._callOnModel = new _base_common_lifecycle_js__WEBPACK_IMPORTED_MODULE_3__[/* DisposableStore */ "b"]();
this._callOnDispose.add(editor.onDidChangeConfiguration(() => this._update()));
this._callOnDispose.add(editor.onDidChangeModel(() => this._update()));
this._callOnDispose.add(editor.onDidChangeModelLanguage(() => this._update()));
this._callOnDispose.add(_common_modes_js__WEBPACK_IMPORTED_MODULE_9__[/* DocumentRangeFormattingEditProviderRegistry */ "j"].onDidChange(this._update, this));
}
dispose() {
this._callOnDispose.dispose();
this._callOnModel.dispose();
}
_update() {
// clean up
this._callOnModel.clear();
// we are disabled
if (!this.editor.getOption(42 /* formatOnPaste */)) {
return;
}
// no model
if (!this.editor.hasModel()) {
return;
}
// no formatter
if (!_common_modes_js__WEBPACK_IMPORTED_MODULE_9__[/* DocumentRangeFormattingEditProviderRegistry */ "j"].has(this.editor.getModel())) {
return;
}
this._callOnModel.add(this.editor.onDidPaste(({ range }) => this._trigger(range)));
}
_trigger(range) {
if (!this.editor.hasModel()) {
return;
}
if (this.editor.getSelections().length > 1) {
return;
}
this._instantiationService.invokeFunction(_format_js__WEBPACK_IMPORTED_MODULE_11__[/* formatDocumentRangesWithSelectedProvider */ "c"], this.editor, range, 2 /* Silent */, _platform_progress_common_progress_js__WEBPACK_IMPORTED_MODULE_18__[/* Progress */ "b"].None, _base_common_cancellation_js__WEBPACK_IMPORTED_MODULE_1__[/* CancellationToken */ "a"].None).catch(_base_common_errors_js__WEBPACK_IMPORTED_MODULE_17__[/* onUnexpectedError */ "e"]);
}
};
FormatOnPaste.ID = 'editor.contrib.formatOnPaste';
FormatOnPaste = __decorate([
__param(1, _platform_instantiation_common_instantiation_js__WEBPACK_IMPORTED_MODULE_16__[/* IInstantiationService */ "a"])
], FormatOnPaste);
class FormatDocumentAction extends _browser_editorExtensions_js__WEBPACK_IMPORTED_MODULE_4__[/* EditorAction */ "b"] {
constructor() {
super({
id: 'editor.action.formatDocument',
label: _nls_js__WEBPACK_IMPORTED_MODULE_13__[/* localize */ "a"]('formatDocument.label', "Format Document"),
alias: 'Format Document',
precondition: _platform_contextkey_common_contextkey_js__WEBPACK_IMPORTED_MODULE_15__[/* ContextKeyExpr */ "a"].and(_common_editorContextKeys_js__WEBPACK_IMPORTED_MODULE_8__[/* EditorContextKeys */ "a"].notInCompositeEditor, _common_editorContextKeys_js__WEBPACK_IMPORTED_MODULE_8__[/* EditorContextKeys */ "a"].writable, _common_editorContextKeys_js__WEBPACK_IMPORTED_MODULE_8__[/* EditorContextKeys */ "a"].hasDocumentFormattingProvider),
kbOpts: {
kbExpr: _common_editorContextKeys_js__WEBPACK_IMPORTED_MODULE_8__[/* EditorContextKeys */ "a"].editorTextFocus,
primary: 1024 /* Shift */ | 512 /* Alt */ | 36 /* KEY_F */,
linux: { primary: 2048 /* CtrlCmd */ | 1024 /* Shift */ | 39 /* KEY_I */ },
weight: 100 /* EditorContrib */
},
contextMenuOpts: {
group: '1_modification',
order: 1.3
}
});
}
run(accessor, editor) {
return __awaiter(this, void 0, void 0, function* () {
if (editor.hasModel()) {
const instaService = accessor.get(_platform_instantiation_common_instantiation_js__WEBPACK_IMPORTED_MODULE_16__[/* IInstantiationService */ "a"]);
const progressService = accessor.get(_platform_progress_common_progress_js__WEBPACK_IMPORTED_MODULE_18__[/* IEditorProgressService */ "a"]);
yield progressService.showWhile(instaService.invokeFunction(_format_js__WEBPACK_IMPORTED_MODULE_11__[/* formatDocumentWithSelectedProvider */ "d"], editor, 1 /* Explicit */, _platform_progress_common_progress_js__WEBPACK_IMPORTED_MODULE_18__[/* Progress */ "b"].None, _base_common_cancellation_js__WEBPACK_IMPORTED_MODULE_1__[/* CancellationToken */ "a"].None), 250);
}
});
}
}
class FormatSelectionAction extends _browser_editorExtensions_js__WEBPACK_IMPORTED_MODULE_4__[/* EditorAction */ "b"] {
constructor() {
super({
id: 'editor.action.formatSelection',
label: _nls_js__WEBPACK_IMPORTED_MODULE_13__[/* localize */ "a"]('formatSelection.label', "Format Selection"),
alias: 'Format Selection',
precondition: _platform_contextkey_common_contextkey_js__WEBPACK_IMPORTED_MODULE_15__[/* ContextKeyExpr */ "a"].and(_common_editorContextKeys_js__WEBPACK_IMPORTED_MODULE_8__[/* EditorContextKeys */ "a"].writable, _common_editorContextKeys_js__WEBPACK_IMPORTED_MODULE_8__[/* EditorContextKeys */ "a"].hasDocumentSelectionFormattingProvider),
kbOpts: {
kbExpr: _common_editorContextKeys_js__WEBPACK_IMPORTED_MODULE_8__[/* EditorContextKeys */ "a"].editorTextFocus,
primary: Object(_base_common_keyCodes_js__WEBPACK_IMPORTED_MODULE_2__[/* KeyChord */ "a"])(2048 /* CtrlCmd */ | 41 /* KEY_K */, 2048 /* CtrlCmd */ | 36 /* KEY_F */),
weight: 100 /* EditorContrib */
},
contextMenuOpts: {
when: _common_editorContextKeys_js__WEBPACK_IMPORTED_MODULE_8__[/* EditorContextKeys */ "a"].hasNonEmptySelection,
group: '1_modification',
order: 1.31
}
});
}
run(accessor, editor) {
return __awaiter(this, void 0, void 0, function* () {
if (!editor.hasModel()) {
return;
}
const instaService = accessor.get(_platform_instantiation_common_instantiation_js__WEBPACK_IMPORTED_MODULE_16__[/* IInstantiationService */ "a"]);
const model = editor.getModel();
const ranges = editor.getSelections().map(range => {
return range.isEmpty()
? new _common_core_range_js__WEBPACK_IMPORTED_MODULE_7__[/* Range */ "a"](range.startLineNumber, 1, range.startLineNumber, model.getLineMaxColumn(range.startLineNumber))
: range;
});
const progressService = accessor.get(_platform_progress_common_progress_js__WEBPACK_IMPORTED_MODULE_18__[/* IEditorProgressService */ "a"]);
yield progressService.showWhile(instaService.invokeFunction(_format_js__WEBPACK_IMPORTED_MODULE_11__[/* formatDocumentRangesWithSelectedProvider */ "c"], editor, ranges, 1 /* Explicit */, _platform_progress_common_progress_js__WEBPACK_IMPORTED_MODULE_18__[/* Progress */ "b"].None, _base_common_cancellation_js__WEBPACK_IMPORTED_MODULE_1__[/* CancellationToken */ "a"].None), 250);
});
}
}
Object(_browser_editorExtensions_js__WEBPACK_IMPORTED_MODULE_4__[/* registerEditorContribution */ "l"])(FormatOnType.ID, FormatOnType);
Object(_browser_editorExtensions_js__WEBPACK_IMPORTED_MODULE_4__[/* registerEditorContribution */ "l"])(FormatOnPaste.ID, FormatOnPaste);
Object(_browser_editorExtensions_js__WEBPACK_IMPORTED_MODULE_4__[/* registerEditorAction */ "j"])(FormatDocumentAction);
Object(_browser_editorExtensions_js__WEBPACK_IMPORTED_MODULE_4__[/* registerEditorAction */ "j"])(FormatSelectionAction);
// this is the old format action that does both (format document OR format selection)
// and we keep it here such that existing keybinding configurations etc will still work
_platform_commands_common_commands_js__WEBPACK_IMPORTED_MODULE_14__[/* CommandsRegistry */ "a"].registerCommand('editor.action.format', (accessor) => __awaiter(void 0, void 0, void 0, function* () {
const editor = accessor.get(_browser_services_codeEditorService_js__WEBPACK_IMPORTED_MODULE_5__[/* ICodeEditorService */ "a"]).getFocusedCodeEditor();
if (!editor || !editor.hasModel()) {
return;
}
const commandService = accessor.get(_platform_commands_common_commands_js__WEBPACK_IMPORTED_MODULE_14__[/* ICommandService */ "b"]);
if (editor.getSelection().isEmpty()) {
yield commandService.executeCommand('editor.action.formatDocument');
}
else {
yield commandService.executeCommand('editor.action.formatSelection');
}
}));
/***/ }),
/***/ "0287":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
// EXPORTS
__webpack_require__.d(__webpack_exports__, "a", function() { return /* binding */ diffEditorWidget_DiffEditorWidget; });
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/editor/browser/widget/media/diffEditor.css
var media_diffEditor = __webpack_require__("df38");
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/nls.js
var nls = __webpack_require__("484b");
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/base/browser/dom.js
var dom = __webpack_require__("98ac");
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/base/browser/fastDomNode.js
var fastDomNode = __webpack_require__("8043");
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/base/browser/ui/sash/sash.js
var sash = __webpack_require__("b467");
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/base/common/async.js
var common_async = __webpack_require__("8879");
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/base/common/event.js
var common_event = __webpack_require__("77cd");
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/base/common/lifecycle.js
var lifecycle = __webpack_require__("e3ad");
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/editor/browser/config/configuration.js + 1 modules
var configuration = __webpack_require__("82f9");
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/editor/browser/core/editorState.js + 1 modules
var editorState = __webpack_require__("e246");
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/editor/browser/services/codeEditorService.js
var services_codeEditorService = __webpack_require__("63d8");
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/editor/browser/widget/codeEditorWidget.js + 58 modules
var codeEditorWidget = __webpack_require__("55a0");
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/editor/browser/widget/media/diffReview.css
var diffReview = __webpack_require__("69ff");
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/base/browser/ui/actionbar/actionbar.js
var actionbar = __webpack_require__("5afa");
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/base/browser/ui/scrollbar/scrollableElement.js + 6 modules
var scrollableElement = __webpack_require__("17cf");
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/base/common/actions.js
var common_actions = __webpack_require__("472b");
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/editor/browser/editorExtensions.js
var editorExtensions = __webpack_require__("3658");
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/editor/common/config/editorOptions.js
var editorOptions = __webpack_require__("d3f6");
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/editor/common/core/lineTokens.js
var core_lineTokens = __webpack_require__("aa13");
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/editor/common/core/position.js
var position = __webpack_require__("bcd3");
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/editor/common/view/editorColorRegistry.js
var editorColorRegistry = __webpack_require__("63ba");
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/editor/common/viewLayout/viewLineRenderer.js
var viewLineRenderer = __webpack_require__("5199");
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/editor/common/viewModel/viewModel.js
var viewModel_viewModel = __webpack_require__("1f2e");
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/platform/contextkey/common/contextkey.js
var contextkey = __webpack_require__("4f24");
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/platform/theme/common/colorRegistry.js
var colorRegistry = __webpack_require__("eb3b");
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/platform/theme/common/themeService.js
var common_themeService = __webpack_require__("2ea8");
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/base/common/codicons.js
var codicons = __webpack_require__("92ea");
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/platform/theme/common/iconRegistry.js
var iconRegistry = __webpack_require__("4460");
// CONCATENATED MODULE: ./node_modules/_monaco-editor@0.23.0@monaco-editor/esm/vs/editor/browser/widget/diffReview.js
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
var _a;
const DIFF_LINES_PADDING = 3;
class DiffEntry {
constructor(originalLineStart, originalLineEnd, modifiedLineStart, modifiedLineEnd) {
this.originalLineStart = originalLineStart;
this.originalLineEnd = originalLineEnd;
this.modifiedLineStart = modifiedLineStart;
this.modifiedLineEnd = modifiedLineEnd;
}
getType() {
if (this.originalLineStart === 0) {
return 1 /* Insert */;
}
if (this.modifiedLineStart === 0) {
return 2 /* Delete */;
}
return 0 /* Equal */;
}
}
class Diff {
constructor(entries) {
this.entries = entries;
}
}
const diffReviewInsertIcon = Object(iconRegistry["b" /* registerIcon */])('diff-review-insert', codicons["b" /* Codicon */].add, nls["a" /* localize */]('diffReviewInsertIcon', 'Icon for \'Insert\' in diff review.'));
const diffReviewRemoveIcon = Object(iconRegistry["b" /* registerIcon */])('diff-review-remove', codicons["b" /* Codicon */].remove, nls["a" /* localize */]('diffReviewRemoveIcon', 'Icon for \'Remove\' in diff review.'));
const diffReviewCloseIcon = Object(iconRegistry["b" /* registerIcon */])('diff-review-close', codicons["b" /* Codicon */].close, nls["a" /* localize */]('diffReviewCloseIcon', 'Icon for \'Close\' in diff review.'));
class diffReview_DiffReview extends lifecycle["a" /* Disposable */] {
constructor(diffEditor) {
super();
this._width = 0;
this._diffEditor = diffEditor;
this._isVisible = false;
this.shadow = Object(fastDomNode["b" /* createFastDomNode */])(document.createElement('div'));
this.shadow.setClassName('diff-review-shadow');
this.actionBarContainer = Object(fastDomNode["b" /* createFastDomNode */])(document.createElement('div'));
this.actionBarContainer.setClassName('diff-review-actions');
this._actionBar = this._register(new actionbar["a" /* ActionBar */](this.actionBarContainer.domNode));
this._actionBar.push(new common_actions["a" /* Action */]('diffreview.close', nls["a" /* localize */]('label.close', "Close"), 'close-diff-review ' + common_themeService["d" /* ThemeIcon */].asClassName(diffReviewCloseIcon), true, () => {
this.hide();
return Promise.resolve(null);
}), { label: false, icon: true });
this.domNode = Object(fastDomNode["b" /* createFastDomNode */])(document.createElement('div'));
this.domNode.setClassName('diff-review monaco-editor-background');
this._content = Object(fastDomNode["b" /* createFastDomNode */])(document.createElement('div'));
this._content.setClassName('diff-review-content');
this._content.setAttribute('role', 'code');
this.scrollbar = this._register(new scrollableElement["a" /* DomScrollableElement */](this._content.domNode, {}));
this.domNode.domNode.appendChild(this.scrollbar.getDomNode());
this._register(diffEditor.onDidUpdateDiff(() => {
if (!this._isVisible) {
return;
}
this._diffs = this._compute();
this._render();
}));
this._register(diffEditor.getModifiedEditor().onDidChangeCursorPosition(() => {
if (!this._isVisible) {
return;
}
this._render();
}));
this._register(dom["n" /* addStandardDisposableListener */](this.domNode.domNode, 'click', (e) => {
e.preventDefault();
let row = dom["w" /* findParentWithClass */](e.target, 'diff-review-row');
if (row) {
this._goToRow(row);
}
}));
this._register(dom["n" /* addStandardDisposableListener */](this.domNode.domNode, 'keydown', (e) => {
if (e.equals(18 /* DownArrow */)
|| e.equals(2048 /* CtrlCmd */ | 18 /* DownArrow */)
|| e.equals(512 /* Alt */ | 18 /* DownArrow */)) {
e.preventDefault();
this._goToRow(this._getNextRow());
}
if (e.equals(16 /* UpArrow */)
|| e.equals(2048 /* CtrlCmd */ | 16 /* UpArrow */)
|| e.equals(512 /* Alt */ | 16 /* UpArrow */)) {
e.preventDefault();
this._goToRow(this._getPrevRow());
}
if (e.equals(9 /* Escape */)
|| e.equals(2048 /* CtrlCmd */ | 9 /* Escape */)
|| e.equals(512 /* Alt */ | 9 /* Escape */)
|| e.equals(1024 /* Shift */ | 9 /* Escape */)) {
e.preventDefault();
this.hide();
}
if (e.equals(10 /* Space */)
|| e.equals(3 /* Enter */)) {
e.preventDefault();
this.accept();
}
}));
this._diffs = [];
this._currentDiff = null;
}
prev() {
let index = 0;
if (!this._isVisible) {
this._diffs = this._compute();
}
if (this._isVisible) {
let currentIndex = -1;
for (let i = 0, len = this._diffs.length; i < len; i++) {
if (this._diffs[i] === this._currentDiff) {
currentIndex = i;
break;
}
}
index = (this._diffs.length + currentIndex - 1);
}
else {
index = this._findDiffIndex(this._diffEditor.getPosition());
}
if (this._diffs.length === 0) {
// Nothing to do
return;
}
index = index % this._diffs.length;
const entries = this._diffs[index].entries;
this._diffEditor.setPosition(new position["a" /* Position */](entries[0].modifiedLineStart, 1));
this._diffEditor.setSelection({ startColumn: 1, startLineNumber: entries[0].modifiedLineStart, endColumn: 1073741824 /* MAX_SAFE_SMALL_INTEGER */, endLineNumber: entries[entries.length - 1].modifiedLineEnd });
this._isVisible = true;
this._diffEditor.doLayout();
this._render();
this._goToRow(this._getNextRow());
}
next() {
let index = 0;
if (!this._isVisible) {
this._diffs = this._compute();
}
if (this._isVisible) {
let currentIndex = -1;
for (let i = 0, len = this._diffs.length; i < len; i++) {
if (this._diffs[i] === this._currentDiff) {
currentIndex = i;
break;
}
}
index = (currentIndex + 1);
}
else {
index = this._findDiffIndex(this._diffEditor.getPosition());
}
if (this._diffs.length === 0) {
// Nothing to do
return;
}
index = index % this._diffs.length;
const entries = this._diffs[index].entries;
this._diffEditor.setPosition(new position["a" /* Position */](entries[0].modifiedLineStart, 1));
this._diffEditor.setSelection({ startColumn: 1, startLineNumber: entries[0].modifiedLineStart, endColumn: 1073741824 /* MAX_SAFE_SMALL_INTEGER */, endLineNumber: entries[entries.length - 1].modifiedLineEnd });
this._isVisible = true;
this._diffEditor.doLayout();
this._render();
this._goToRow(this._getNextRow());
}
accept() {
let jumpToLineNumber = -1;
let current = this._getCurrentFocusedRow();
if (current) {
let lineNumber = parseInt(current.getAttribute('data-line'), 10);
if (!isNaN(lineNumber)) {
jumpToLineNumber = lineNumber;
}
}
this.hide();
if (jumpToLineNumber !== -1) {
this._diffEditor.setPosition(new position["a" /* Position */](jumpToLineNumber, 1));
this._diffEditor.revealPosition(new position["a" /* Position */](jumpToLineNumber, 1), 1 /* Immediate */);
}
}
hide() {
this._isVisible = false;
this._diffEditor.updateOptions({ readOnly: false });
this._diffEditor.focus();
this._diffEditor.doLayout();
this._render();
}
_getPrevRow() {
let current = this._getCurrentFocusedRow();
if (!current) {
return this._getFirstRow();
}
if (current.previousElementSibling) {
return current.previousElementSibling;
}
return current;
}
_getNextRow() {
let current = this._getCurrentFocusedRow();
if (!current) {
return this._getFirstRow();
}
if (current.nextElementSibling) {
return current.nextElementSibling;
}
return current;
}
_getFirstRow() {
return this.domNode.domNode.querySelector('.diff-review-row');
}
_getCurrentFocusedRow() {
let result = document.activeElement;
if (result && /diff-review-row/.test(result.className)) {
return result;
}
return null;
}
_goToRow(row) {
let prev = this._getCurrentFocusedRow();
row.tabIndex = 0;
row.focus();
if (prev && prev !== row) {
prev.tabIndex = -1;
}
this.scrollbar.scanDomNode();
}
isVisible() {
return this._isVisible;
}
layout(top, width, height) {
this._width = width;
this.shadow.setTop(top - 6);
this.shadow.setWidth(width);
this.shadow.setHeight(this._isVisible ? 6 : 0);
this.domNode.setTop(top);
this.domNode.setWidth(width);
this.domNode.setHeight(height);
this._content.setHeight(height);
this._content.setWidth(width);
if (this._isVisible) {
this.actionBarContainer.setAttribute('aria-hidden', 'false');
this.actionBarContainer.setDisplay('block');
}
else {
this.actionBarContainer.setAttribute('aria-hidden', 'true');
this.actionBarContainer.setDisplay('none');
}
}
_compute() {
const lineChanges = this._diffEditor.getLineChanges();
if (!lineChanges || lineChanges.length === 0) {
return [];
}
const originalModel = this._diffEditor.getOriginalEditor().getModel();
const modifiedModel = this._diffEditor.getModifiedEditor().getModel();
if (!originalModel || !modifiedModel) {
return [];
}
return diffReview_DiffReview._mergeAdjacent(lineChanges, originalModel.getLineCount(), modifiedModel.getLineCount());
}
static _mergeAdjacent(lineChanges, originalLineCount, modifiedLineCount) {
if (!lineChanges || lineChanges.length === 0) {
return [];
}
let diffs = [], diffsLength = 0;
for (let i = 0, len = lineChanges.length; i < len; i++) {
const lineChange = lineChanges[i];
const originalStart = lineChange.originalStartLineNumber;
const originalEnd = lineChange.originalEndLineNumber;
const modifiedStart = lineChange.modifiedStartLineNumber;
const modifiedEnd = lineChange.modifiedEndLineNumber;
let r = [], rLength = 0;
// Emit before anchors
{
const originalEqualAbove = (originalEnd === 0 ? originalStart : originalStart - 1);
const modifiedEqualAbove = (modifiedEnd === 0 ? modifiedStart : modifiedStart - 1);
// Make sure we don't step into the previous diff
let minOriginal = 1;
let minModified = 1;
if (i > 0) {
const prevLineChange = lineChanges[i - 1];
if (prevLineChange.originalEndLineNumber === 0) {
minOriginal = prevLineChange.originalStartLineNumber + 1;
}
else {
minOriginal = prevLineChange.originalEndLineNumber + 1;
}
if (prevLineChange.modifiedEndLineNumber === 0) {
minModified = prevLineChange.modifiedStartLineNumber + 1;
}
else {
minModified = prevLineChange.modifiedEndLineNumber + 1;
}
}
let fromOriginal = originalEqualAbove - DIFF_LINES_PADDING + 1;
let fromModified = modifiedEqualAbove - DIFF_LINES_PADDING + 1;
if (fromOriginal < minOriginal) {
const delta = minOriginal - fromOriginal;
fromOriginal = fromOriginal + delta;
fromModified = fromModified + delta;
}
if (fromModified < minModified) {
const delta = minModified - fromModifi