Merge pull request #6987 from atom/ns-fix-buffer-range-for-scope-at-position

Use previous definition of scope selector match to fix API breakage
This commit is contained in:
Kevin Sawicki
2015-05-28 08:11:05 -07:00
2 changed files with 11 additions and 5 deletions

View File

@@ -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", ->

View File

@@ -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)