Spans have a class for each dot-separated portion of their token's scope

Previously, we were rendering every prefix of the dot-separated scope as its own class. So the scope meta.delimiter.method.period.coffee would make a token w/ classes:

class="meta, meta-delimiter, meta-delimiter-method, meta-delimiter-method-period…"

Now we just give the token each piece of the scope as a class:

class="meta delimiter method period coffee"

We lose a bit of meaning, in that a scope selector method.period.coffee would match this element in CSS even though it *wouldn't* in TextMate. But we also gain the behavior where longer prefixes are more specific by naturally producing more specific css selectors. So '.meta.delimiter.method' is always more specific than '.meta.delimiter', whereas '.meta-delimiter-method' ties with '.meta-delimiter'. 

If prefix ambiguities become a problem later we may need to revisit this approach, but I think it's good enough for now.
This commit is contained in:
Nathan Sobo
2012-09-28 17:00:31 -06:00
parent dc4d981e2a
commit 3a8fe2b24e
4 changed files with 15 additions and 18 deletions

View File

@@ -832,10 +832,7 @@ class Editor extends View
pushScope = (scope) ->
scopeStack.push(scope)
classes = []
scopeComponents = scope.split('.')
classes.push scopeComponents[0..i].join('-') for i in [0...scopeComponents.length]
line.push("<span class=\"#{classes.join(' ')}\">")
line.push("<span class=\"#{scope.replace(/\./g, ' ')}\">")
popScope = ->
scopeStack.pop()

View File

@@ -81,7 +81,7 @@ class TextMateTheme
properties: @translateScopeSelectorSettings(settings)
translateScopeSelector: (textmateScopeSelector) ->
scopes = textmateScopeSelector.replace(/\./g, '-').split(/\s+/).map (scope) -> '.' + scope
scopes = textmateScopeSelector.split(/\s+/).map (scope) -> '.' + scope
scopes.join(' ')
translateScopeSelectorSettings: ({ foreground, background, fontStyle }) ->