import { Range , window , TextEditor } from 'vscode' ; import { getCssPropertyFromRule , getCssPropertyFromDocument } from './util' ; import { Property , Rule } from 'EmmetNode' ; const vendorPrefixes = [ '-webkit-' , '-moz-' , '-ms-' , '-o-' , '' ] ; export function reflectCssValue ( ) { let editor = window . activeTextEditor ; if ( ! editor ) { window . showInformationMessage ( 'No editor is active.' ) ; return ; } let node = getCssPropertyFromDocument ( editor , editor . selection . active ) ; if ( ! node ) { return ; } return updateCSSNode ( editor , node ) ; } function updateCSSNode ( editor , property ) { const rule = property . parent ; let currentPrefix = '' ; for ( const prefix of vendorPrefixes ) { if ( property . name . startsWith ( prefix ) ) { currentPrefix = prefix ; break ; } } const propertyName = property . name . substr ( currentPrefix . length ) ; const propertyValue = property . value ; return editor . edit ( builder => { vendorPrefixes . forEach ( prefix => { if ( prefix === currentPrefix ) { return ; } let vendorProperty = getCssPropertyFromRule ( rule , prefix + propertyName ) ; if ( vendorProperty ) { builder . replace ( new Range ( vendorProperty . valueToken . start , vendorProperty . valueToken . end ) , propertyValue ) ; } } ) ; } ) ; }