From 31cf19a205f953cc9f800afa52d72e9f319d1d7a Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 28 May 2015 10:38:20 +0200 Subject: [PATCH] Use previous definition of scope selector match to fix API breakage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I switched to first-mate Selector because I didn’t want to replicate the poorly-defined Token::matchesScopeSelector method now that tokens are not stored on lines. However, the first-mate semantics are stricter and that broke the API. Perhaps using selector-kit here would be better, but I just wanted to put back exactly to how it was for now. /cc @ypresto --- spec/tokenized-buffer-spec.coffee | 2 +- src/tokenized-buffer.coffee | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) 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)