import * as vscode from 'vscode' ; import { HtmlNode } from 'EmmetNode' ; import { getHtmlNode , parseDocument , validate } from './util' ; export function matchTag ( ) { if ( ! validate ( false ) || ! vscode . window . activeTextEditor ) { return ; } const editor = vscode . window . activeTextEditor ; let rootNode = < HtmlNode > parseDocument ( editor . document ) ; if ( ! rootNode ) { return ; } let updatedSelections = [ ] ; editor . selections . forEach ( selection => { let updatedSelection = getUpdatedSelections ( editor , selection . start , rootNode ) ; if ( updatedSelection ) { updatedSelections . push ( updatedSelection ) ; } } ) ; if ( updatedSelections . length > 0 ) { editor . selections = updatedSelections ; editor . revealRange ( editor . selections [ updatedSelections . length - 1 ] ) ; } } function getUpdatedSelections ( editor , position , rootNode ) { let currentNode = getHtmlNode ( editor . document , rootNode , position , true ) ; if ( ! currentNode ) { return ; } if ( ! currentNode . close || ( position . isAfter ( currentNode . open . end ) && position . isBefore ( currentNode . close . start ) ) ) { return ; } let finalPosition = position . isBeforeOrEqual ( currentNode . open . end ) ? currentNode . close . start . translate ( 0 , 2 ) : currentNode . open . start . translate ( 0 , 1 ) ; return new vscode . Selection ( finalPosition , finalPosition ) ; }