diff --git a/spec/tokenized-buffer-spec.coffee b/spec/tokenized-buffer-spec.coffee index 9d94cb80a..dc57d3fee 100644 --- a/spec/tokenized-buffer-spec.coffee +++ b/spec/tokenized-buffer-spec.coffee @@ -572,7 +572,7 @@ describe "TokenizedBuffer", -> describe "when the selector matches a run of multiple tokens at the position", -> it "returns the range covered by all contigous tokens (within a single line)", -> - expect(tokenizedBuffer.bufferRangeForScopeAtPosition('.meta.function', [1, 18])).toEqual [[1, 6], [1, 28]] + expect(tokenizedBuffer.bufferRangeForScopeAtPosition('.function', [1, 18])).toEqual [[1, 6], [1, 28]] describe "when the editor.tabLength config value changes", -> it "updates the tab length of the tokenized lines", -> diff --git a/src/tokenized-buffer.coffee b/src/tokenized-buffer.coffee index 60ebe16f0..55d2e7e37 100644 --- a/src/tokenized-buffer.coffee +++ b/src/tokenized-buffer.coffee @@ -426,7 +426,6 @@ class TokenizedBuffer extends Model new Point(row, column) bufferRangeForScopeAtPosition: (selector, position) -> - selector = new ScopeSelector(selector.replace(/^\./, '')) position = Point.fromObject(position) {openScopes, tags} = @tokenizedLines[position.row] @@ -446,7 +445,8 @@ class TokenizedBuffer extends Model else startColumn = endColumn - return unless selector.matches(scopes) + + return unless selectorMatchesAnyScope(selector, scopes) startScopes = scopes.slice() for startTokenIndex in [(tokenIndex - 1)..0] by -1 @@ -457,7 +457,7 @@ class TokenizedBuffer extends Model else startScopes.push(atom.grammars.scopeForId(tag)) else - break unless selector.matches(startScopes) + break unless selectorMatchesAnyScope(selector, startScopes) startColumn -= tag endScopes = scopes.slice() @@ -469,7 +469,7 @@ class TokenizedBuffer extends Model else endScopes.pop() else - break unless selector.matches(endScopes) + break unless selectorMatchesAnyScope(selector, endScopes) endColumn += tag new Range(new Point(position.row, startColumn), new Point(position.row, endColumn)) @@ -504,3 +504,9 @@ if Grim.includeDeprecatedAPIs Grim.deprecate("TokenizedBuffer::on is deprecated. Use event subscription methods instead.") EmitterMixin::on.apply(this, arguments) + +selectorMatchesAnyScope = (selector, scopes) -> + targetClasses = selector.replace(/^\./, '').split('.') + _.any scopes, (scope) -> + scopeClasses = scope.split('.') + _.isSubset(targetClasses, scopeClasses)