mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Support scope selectors with dashes in segments
Previously dashes were only interpreted as negation which wasn't correct. Segments should be able to contain a dash as long as it isn't at the very beginning of the segment.
This commit is contained in:
@@ -13,6 +13,8 @@ describe "TextMateScopeSelector", ->
|
||||
expect(new TextMateScopeSelector('a').matches(['a.b'])).toBeTruthy()
|
||||
expect(new TextMateScopeSelector('a.b').matches(['a.b.c'])).toBeTruthy()
|
||||
expect(new TextMateScopeSelector('a').matches(['abc'])).toBeFalsy()
|
||||
expect(new TextMateScopeSelector('a.b-c').matches(['a.b-c.d'])).toBeTruthy()
|
||||
expect(new TextMateScopeSelector('a.b').matches(['a.b-d'])).toBeFalsy()
|
||||
|
||||
it "matches disjunction", ->
|
||||
expect(new TextMateScopeSelector('a | b').matches(['b'])).toBeTruthy()
|
||||
@@ -22,6 +24,9 @@ describe "TextMateScopeSelector", ->
|
||||
it "matches negation", ->
|
||||
expect(new TextMateScopeSelector('a - c').matches(['a', 'b'])).toBeTruthy()
|
||||
expect(new TextMateScopeSelector('a-b').matches(['a', 'b'])).toBeFalsy()
|
||||
expect(new TextMateScopeSelector('a -b').matches(['a', 'b'])).toBeFalsy()
|
||||
expect(new TextMateScopeSelector('a -c').matches(['a', 'b'])).toBeTruthy()
|
||||
expect(new TextMateScopeSelector('a-c').matches(['a', 'b'])).toBeFalsy()
|
||||
|
||||
it "matches conjunction", ->
|
||||
expect(new TextMateScopeSelector('a & b').matches(['b', 'a'])).toBeTruthy()
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
_ = require 'underscore'
|
||||
|
||||
### Internal ###
|
||||
|
||||
class SegmentMatcher
|
||||
constructor: (segment) ->
|
||||
@segment = segment.join('')
|
||||
@segment = _.flatten(segment).join('')
|
||||
|
||||
matches: (scope) ->
|
||||
scope is @segment
|
||||
|
||||
@@ -7,7 +7,7 @@ start = _ selector:(selector) _ {
|
||||
}
|
||||
|
||||
segment
|
||||
= _ segment:[a-zA-Z0-9]+ _ {
|
||||
= _ segment:([a-zA-Z0-9]+[a-zA-Z0-9-]*) _ {
|
||||
return new matchers.SegmentMatcher(segment);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user