mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-23 01:58:53 +01:00
Continue moving emmet extension to strict mode. This change does the following: - Remove jsdoc types. These are unused in ts files and can easily get out of date - Annotate when something can return undefined - Add null checks for when something can be undefined - Add explicit types when something can be any
54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
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(): Thenable<boolean> | undefined {
|
|
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: TextEditor, property: Property): Thenable<boolean> {
|
|
const rule: Rule = property.parent;
|
|
let currentPrefix = '';
|
|
|
|
// Find vendor prefix of given property node
|
|
for (let i = 0; i < vendorPrefixes.length; i++) {
|
|
if (property.name.startsWith(vendorPrefixes[i])) {
|
|
currentPrefix = vendorPrefixes[i];
|
|
break;
|
|
}
|
|
}
|
|
|
|
const propertyName = property.name.substr(currentPrefix.length);
|
|
const propertyValue = property.value;
|
|
|
|
return editor.edit(builder => {
|
|
// Find properties with vendor prefixes, update each
|
|
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);
|
|
}
|
|
});
|
|
});
|
|
} |