Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
octref committed Jan 17, 2019
1 parent 0263d26 commit 05f8659
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 16 additions & 3 deletions src/emmetHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let markupSnippetKeysRegex: RegExp[];
const stylesheetCustomSnippetsKeyCache = new Map<string, string[]>();
const htmlAbbreviationStartRegex = /^[a-z,A-Z,!,(,[,#,\.]/;
const cssAbbreviationRegex = /^-?[a-z,A-Z,!,@,#]/;
const htmlAbbreviationRegex = /[a-z,A-Z]/;
const htmlAbbreviationRegex = /[a-z,A-Z\.]/;
const emmetModes = ['html', 'pug', 'slim', 'haml', 'xml', 'xsl', 'jsx', 'css', 'scss', 'sass', 'less', 'stylus'];
const commonlyUsedTags = [...htmlData.tags, 'lorem'];
const bemFilterSuffix = 'bem';
Expand Down Expand Up @@ -256,7 +256,7 @@ function makeSnippetSuggestion(snippetKeys: string[], prefix: string, abbreviati

function getCurrentWord(currentLineTillPosition: string): string {
if (currentLineTillPosition) {
let matches = currentLineTillPosition.match(/[\w,:,-]*$/);
let matches = currentLineTillPosition.match(/[\w,:,-,\.]*$/)
if (matches) {
return matches[0];
}
Expand Down Expand Up @@ -517,7 +517,20 @@ function isExpandedTextNoise(syntax: string, abbreviation: string, expandedText:

// Its common for users to type some text and end it with period, this should not be treated as an abbreviation
// Else it becomes noise.
if (/^[a-z,A-Z,\d]*\.$/.test(abbreviation)) {

// When user just types '.', return the expansion
// Otherwise emmet loses change to participate later
// For example in `.foo`. See https://github.com/Microsoft/vscode/issues/66013
if (abbreviation === '.') {
return false;
}

const dotMatches = abbreviation.match(/^([a-z,A-Z,\d]*)\.$/)
if (dotMatches) {
// Valid html tags such as `div.`
if (dotMatches[1] && htmlData.tags.includes(dotMatches[1])) {
return false
}
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/emmetHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const expectedBemCommentFilterOutputDocs = expectedBemCommentFilterOutput.replac

describe('Validate Abbreviations', () => {
it('should return true for valid abbreviations', () => {
const htmlAbbreviations = ['ul>li', 'ul', 'h1', 'ul>li*3', '(ul>li)+div', '.hello', '!', '#hello', '.item[id=ok]'];
const htmlAbbreviations = ['ul>li', 'ul', 'h1', 'ul>li*3', '(ul>li)+div', '.hello', '!', '#hello', '.item[id=ok]', '.', '.foo'];
const cssAbbreviations = ['#123', '#abc'];
htmlAbbreviations.forEach(abbr => {
assert(isAbbreviationValid('html', abbr));
Expand Down

0 comments on commit 05f8659

Please sign in to comment.