diff --git a/src/grammar.ts b/src/grammar.ts index c54f7db..b4639cd 100644 --- a/src/grammar.ts +++ b/src/grammar.ts @@ -357,7 +357,9 @@ function matchInjections(injections:Injection[], grammar: Grammar, lineText: Oni let matchRating = matchResult.captureIndices[0].start; - if (matchRating >= bestMatchRating) { + if (matchRating > bestMatchRating) { + continue; + } else if (matchRating === bestMatchRating && (!injection.priorityMatch || bestMatchResultPriority)) { continue; } diff --git a/test-cases/suite1/fixtures/html.json b/test-cases/suite1/fixtures/html.json new file mode 100644 index 0000000..c321b35 --- /dev/null +++ b/test-cases/suite1/fixtures/html.json @@ -0,0 +1,542 @@ +{ + "fileTypes": [ + "html", + "htm", + "shtml", + "xhtml", + "inc", + "tmpl", + "tpl" + ], + "firstLineMatch": "<(?i:(!DOCTYPE\\s*)?html)", + "injections": { + "R:text.html - comment.block": { + "comment": "Use R: to ensure this matches after any other injections.", + "patterns": [ + { + "match": "<", + "name": "invalid.illegal.bad-angle-bracket.html" + } + ] + } + }, + "keyEquivalent": "^~H", + "name": "HTML", + "patterns": [ + { + "begin": "(<)([a-zA-Z0-9:]++)(?=[^>]*>)", + "beginCaptures": { + "1": { + "name": "punctuation.definition.tag.html" + }, + "2": { + "name": "entity.name.tag.html" + } + }, + "end": "(>(<)/)(\\2)(>)", + "endCaptures": { + "1": { + "name": "punctuation.definition.tag.html" + }, + "2": { + "name": "meta.scope.between-tag-pair.html" + }, + "3": { + "name": "entity.name.tag.html" + }, + "4": { + "name": "punctuation.definition.tag.html" + } + }, + "name": "meta.tag.any.html", + "patterns": [ + { + "include": "#tag-stuff" + } + ] + }, + { + "begin": "(<\\?)(xml)", + "captures": { + "1": { + "name": "punctuation.definition.tag.html" + }, + "2": { + "name": "entity.name.tag.xml.html" + } + }, + "end": "(\\?>)", + "name": "meta.tag.preprocessor.xml.html", + "patterns": [ + { + "include": "#tag-generic-attribute" + }, + { + "include": "#string-double-quoted" + }, + { + "include": "#string-single-quoted" + } + ] + }, + { + "begin": "