/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ /** * Describes what to do with the indentation when pressing Enter. */ export var IndentAction; (function (IndentAction) { /** * Insert new line and copy the previous line's indentation. */ IndentAction[IndentAction["None"] = 0] = "None"; /** * Insert new line and indent once (relative to the previous line's indentation). */ IndentAction[IndentAction["Indent"] = 1] = "Indent"; /** * Insert two new lines: * - the first one indented which will hold the cursor * - the second one at the same indentation level */ IndentAction[IndentAction["IndentOutdent"] = 2] = "IndentOutdent"; /** * Insert new line and outdent once (relative to the previous line's indentation). */ IndentAction[IndentAction["Outdent"] = 3] = "Outdent"; })(IndentAction || (IndentAction = {})); /** * @internal */ export class StandardAutoClosingPairConditional { constructor(source) { this._neutralCharacter = null; this._neutralCharacterSearched = false; this.open = source.open; this.close = source.close; // initially allowed in all tokens this._standardTokenMask = 0; if (Array.isArray(source.notIn)) { for (let i = 0, len = source.notIn.length; i < len; i++) { const notIn = source.notIn[i]; switch (notIn) { case 'string': this._standardTokenMask |= 2 /* String */; break; case 'comment': this._standardTokenMask |= 1 /* Comment */; break; case 'regex': this._standardTokenMask |= 4 /* RegEx */; break; } } } } isOK(standardToken) { return (this._standardTokenMask & standardToken) === 0; } shouldAutoClose(context, column) { // Always complete on empty line if (context.getTokenCount() === 0) { return true; } const tokenIndex = context.findTokenIndexAtOffset(column - 2); const standardTokenType = context.getStandardTokenType(tokenIndex); return this.isOK(standardTokenType); } _findNeutralCharacterInRange(fromCharCode, toCharCode) { for (let charCode = fromCharCode; charCode <= toCharCode; charCode++) { const character = String.fromCharCode(charCode); if (!this.open.includes(character) && !this.close.includes(character)) { return character; } } return null; } /** * Find a character in the range [0-9a-zA-Z] that does not appear in the open or close */ findNeutralCharacter() { if (!this._neutralCharacterSearched) { this._neutralCharacterSearched = true; if (!this._neutralCharacter) { this._neutralCharacter = this._findNeutralCharacterInRange(48 /* Digit0 */, 57 /* Digit9 */); } if (!this._neutralCharacter) { this._neutralCharacter = this._findNeutralCharacterInRange(97 /* a */, 122 /* z */); } if (!this._neutralCharacter) { this._neutralCharacter = this._findNeutralCharacterInRange(65 /* A */, 90 /* Z */); } } return this._neutralCharacter; } } /** * @internal */ export class AutoClosingPairs { constructor(autoClosingPairs) { this.autoClosingPairsOpenByStart = new Map(); this.autoClosingPairsOpenByEnd = new Map(); this.autoClosingPairsCloseByStart = new Map(); this.autoClosingPairsCloseByEnd = new Map(); this.autoClosingPairsCloseSingleChar = new Map(); for (const pair of autoClosingPairs) { appendEntry(this.autoClosingPairsOpenByStart, pair.open.charAt(0), pair); appendEntry(this.autoClosingPairsOpenByEnd, pair.open.charAt(pair.open.length - 1), pair); appendEntry(this.autoClosingPairsCloseByStart, pair.close.charAt(0), pair); appendEntry(this.autoClosingPairsCloseByEnd, pair.close.charAt(pair.close.length - 1), pair); if (pair.close.length === 1 && pair.open.length === 1) { appendEntry(this.autoClosingPairsCloseSingleChar, pair.close, pair); } } } } function appendEntry(target, key, value) { if (target.has(key)) { target.get(key).push(value); } else { target.set(key, [value]); } }