| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- /*---------------------------------------------------------------------------------------------
- * Copyright (c) Microsoft Corporation. All rights reserved.
- * Licensed under the MIT License. See License.txt in the project root for license information.
- *--------------------------------------------------------------------------------------------*/
- function resetGlobalRegex(reg) {
- if (reg.global) {
- reg.lastIndex = 0;
- }
- return true;
- }
- export class IndentRulesSupport {
- constructor(indentationRules) {
- this._indentationRules = indentationRules;
- }
- shouldIncrease(text) {
- if (this._indentationRules) {
- if (this._indentationRules.increaseIndentPattern && resetGlobalRegex(this._indentationRules.increaseIndentPattern) && this._indentationRules.increaseIndentPattern.test(text)) {
- return true;
- }
- // if (this._indentationRules.indentNextLinePattern && this._indentationRules.indentNextLinePattern.test(text)) {
- // return true;
- // }
- }
- return false;
- }
- shouldDecrease(text) {
- if (this._indentationRules && this._indentationRules.decreaseIndentPattern && resetGlobalRegex(this._indentationRules.decreaseIndentPattern) && this._indentationRules.decreaseIndentPattern.test(text)) {
- return true;
- }
- return false;
- }
- shouldIndentNextLine(text) {
- if (this._indentationRules && this._indentationRules.indentNextLinePattern && resetGlobalRegex(this._indentationRules.indentNextLinePattern) && this._indentationRules.indentNextLinePattern.test(text)) {
- return true;
- }
- return false;
- }
- shouldIgnore(text) {
- // the text matches `unIndentedLinePattern`
- if (this._indentationRules && this._indentationRules.unIndentedLinePattern && resetGlobalRegex(this._indentationRules.unIndentedLinePattern) && this._indentationRules.unIndentedLinePattern.test(text)) {
- return true;
- }
- return false;
- }
- getIndentMetadata(text) {
- let ret = 0;
- if (this.shouldIncrease(text)) {
- ret += 1 /* IndentConsts.INCREASE_MASK */;
- }
- if (this.shouldDecrease(text)) {
- ret += 2 /* IndentConsts.DECREASE_MASK */;
- }
- if (this.shouldIndentNextLine(text)) {
- ret += 4 /* IndentConsts.INDENT_NEXTLINE_MASK */;
- }
- if (this.shouldIgnore(text)) {
- ret += 8 /* IndentConsts.UNINDENT_MASK */;
- }
- return ret;
- }
- }
|