Skip to content

Commit

Permalink
Dont trigger emmet for # in selectors Fixes #49269
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed May 31, 2018
1 parent 8251be5 commit 90581c7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
5 changes: 4 additions & 1 deletion extensions/emmet/src/abbreviationActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Node, HtmlNode, Rule, Property, Stylesheet } from 'EmmetNode';
import { getEmmetHelper, getNode, getInnerRange, getMappingForIncludedLanguages, parseDocument, validate, getEmmetConfiguration, isStyleSheet, getEmmetMode, parsePartialStylesheet, isStyleAttribute, getEmbeddedCssNodeIfAny } from './util';

const trimRegex = /[\u00a0]*[\d|#|\-|\*|\u2022]+\.?/;
const hexColorRegex = /^#\d+$/;
const hexColorRegex = /^#[\d,a-f,A-F]{0,6}$/;
const allowedMimeTypesInScriptTag = ['text/html', 'text/plain', 'text/x-template', 'text/template'];
const inlineElements = ['a', 'abbr', 'acronym', 'applet', 'b', 'basefont', 'bdo',
'big', 'br', 'button', 'cite', 'code', 'del', 'dfn', 'em', 'font', 'i',
Expand Down Expand Up @@ -402,6 +402,9 @@ export function isValidLocationForEmmetAbbreviation(document: vscode.TextDocumen
&& abbreviation.indexOf(':') === -1) {
return hexColorRegex.test(abbreviation) || abbreviation === '!';
}
if (hexColorRegex.test(abbreviation) || abbreviation === '!') {
return false;
}
}

// If current node is a rule or at-rule, then perform additional checks to ensure
Expand Down
22 changes: 22 additions & 0 deletions extensions/emmet/src/test/cssAbbreviationAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,28 @@ nav#
});
});

test('# shouldnt expand to hex color when in selector (CSS)', () => {
const testContent = `
.foo {
#
}
`;

return withRandomFileEditor(testContent, 'css', (editor, doc) => {
editor.selection = new Selection(2, 2, 2, 2);
return expandEmmetAbbreviation(null).then(() => {
assert.equal(editor.document.getText(), testContent);
const cancelSrc = new CancellationTokenSource();
const completionPromise = completionProvider.provideCompletionItems(editor.document, new Position(2, 2), cancelSrc.token, { triggerKind: CompletionTriggerKind.Invoke });
if (completionPromise) {
assert.equal(1, 2, `Invalid completion of hex color at property name`);
}
return Promise.resolve();
});
});
});


test('Expand abbreviation in completion list (CSS)', () => {
const abbreviation = 'pos:f';
const expandedText = 'position: fixed;';
Expand Down
12 changes: 6 additions & 6 deletions extensions/emmet/src/test/partialParsingStylesheet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ p {
const sassContents = `
.foo
// .foo { brs
/* .foo { op.3
/* .foo { op.3
dn {
*/
@
Expand All @@ -80,7 +80,7 @@ dn {

test('Block comment between selector and open brace', function (): any {
const cssContents = `
p
p
/* First line
of a multiline
comment */
Expand Down Expand Up @@ -197,7 +197,6 @@ p.#{dn} {
return withRandomFileEditor(sassContents, '.scss', (editor, doc) => {
let rangesForEmmet = [
new vscode.Range(2, 1, 2, 4), // p.3 inside a ruleset whose selector uses interpolation
new vscode.Range(3, 1, 3, 2), // # inside ruleset
new vscode.Range(4, 1, 4, 3) // dn inside ruleset after property with variable
];
let rangesNotEmmet = [
Expand All @@ -206,7 +205,8 @@ p.#{dn} {
new vscode.Range(1, 4, 1, 6), // In dn inside variable in selector
new vscode.Range(3, 7, 3, 8), // r of attr inside variable
new vscode.Range(5, 2, 5, 4), // op after ruleset
new vscode.Range(7, 1, 7, 3) // dn inside ruleset whose selector uses nested interpolation
new vscode.Range(7, 1, 7, 3), // dn inside ruleset whose selector uses nested interpolation
new vscode.Range(3, 1, 3, 2), // # inside ruleset
];
rangesForEmmet.forEach(range => {
assert.equal(isValid(doc, range, 'scss'), true);
Expand All @@ -230,7 +230,7 @@ om
ment */{
m10
}
.boo{
.boo{
op.3
}
`;
Expand All @@ -256,5 +256,5 @@ ment */{
});
});


});

0 comments on commit 90581c7

Please sign in to comment.