diff --git a/spec/app/text-mate-grammar-spec.coffee b/spec/app/text-mate-grammar-spec.coffee index 51ca1c483..52b751e8b 100644 --- a/spec/app/text-mate-grammar-spec.coffee +++ b/spec/app/text-mate-grammar-spec.coffee @@ -14,6 +14,7 @@ describe "TextMateGrammar", -> atom.activatePackage('ruby.tmbundle', sync: true) atom.activatePackage('html.tmbundle', sync: true) atom.activatePackage('php.tmbundle', sync: true) + atom.activatePackage('hyperlink-helper.tmbundle', sync: true) grammar = syntax.selectGrammar("hello.coffee") describe "@loadSync(path)", -> @@ -426,3 +427,9 @@ describe "TextMateGrammar", -> expect(tokens[17].value).toBe "div" expect(tokens[17].scopes).toEqual ["text.html.php", "meta.tag.block.any.html", "entity.name.tag.block.any.html"] + + describe "when the grammar's pattern name has a group number in it", -> + it "replaces the group number with the matched captured text", -> + grammar = syntax.grammarForScopeName("text.hyperlink") + {tokens} = grammar.tokenizeLine("https://github.com") + expect(tokens[0].scopes).toEqual ["text.hyperlink", "markup.underline.link.https.hyperlink"] diff --git a/src/app/text-mate-grammar.coffee b/src/app/text-mate-grammar.coffee index 56d168c2b..599b532f2 100644 --- a/src/app/text-mate-grammar.coffee +++ b/src/app/text-mate-grammar.coffee @@ -404,7 +404,14 @@ class Pattern handleMatch: (stack, line, captureIndices) -> scopes = scopesFromStack(stack) - scopes.push(@scopeName) if @scopeName and not @popRule + if @scopeName and not @popRule + patternScope = @scopeName.replace /\$\d+/, (match) -> + captureIndex = parseInt(match.substring(1)) * 3 + if captureIndices[captureIndex]? + line.substr(captureIndices[captureIndex + 1], captureIndices[captureIndex + 2]) + else + match + scopes.push(patternScope) if @captures tokens = @getTokensForCaptureIndices(line, _.clone(captureIndices), scopes, stack)