Skip to content

Commit

Permalink
Use regex in excluded tags
Browse files Browse the repository at this point in the history
  • Loading branch information
yassinecc committed Feb 16, 2019
1 parent a42055d commit dd640a9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ export function activate(context: vscode.ExtensionContext) {
export function deactivate() {
}

function isTagExcluded(tag:string, excludedTags:string[]): boolean {
if (excludedTags.length < 1) {
return false;
}
let regex = new RegExp(excludedTags.join('|'));
return regex.test(tag);
}

function insertAutoCloseTag(event: vscode.TextDocumentChangeEvent): void {
if (!event.contentChanges[0]) {
return;
Expand Down Expand Up @@ -81,7 +89,7 @@ function insertAutoCloseTag(event: vscode.TextDocumentChangeEvent): void {
if (result !== null && ((occurrenceCount(result[0], "'") % 2 === 0)
&& (occurrenceCount(result[0], "\"") % 2 === 0) && (occurrenceCount(result[0], "`") % 2 === 0))) {
if (result[2] === ">") {
if (excludedTags.indexOf(result[1].toLowerCase()) === -1) {
if (!isTagExcluded(result[1].toLowerCase(), excludedTags)) {
editor.edit((editBuilder) => {
editBuilder.insert(originalPosition, "</" + result[1] + ">");
}).then(() => {
Expand Down Expand Up @@ -143,7 +151,7 @@ function getCloseTag(text: string, excludedTags: string[]): string {
while ((result = regex.exec(text)) !== null) {
let isStartTag = result[1].substr(0, 1) !== "/";
let tag = isStartTag ? result[1] : result[1].substr(1);
if (excludedTags.indexOf(tag.toLowerCase()) === -1) {
if (!isTagExcluded(tag.toLowerCase(), excludedTags)) {
if (isStartTag) {
stack.push(tag);
} else if (stack.length > 0) {
Expand Down

0 comments on commit dd640a9

Please sign in to comment.