fix for internal extra commas in theme scopes
This commit is contained in:
@@ -114,11 +114,14 @@ class Theme(NamedTuple):
|
||||
for rule in rules:
|
||||
if 'scope' not in rule:
|
||||
scopes = ['']
|
||||
elif rule['scope'] == '':
|
||||
scopes = ['']
|
||||
elif isinstance(rule['scope'], str):
|
||||
scopes = [
|
||||
s.strip()
|
||||
# some themes have a buggy trailing/leading comma
|
||||
for s in rule['scope'].strip().strip(',').split(',')
|
||||
if s.strip()
|
||||
]
|
||||
else:
|
||||
scopes = rule['scope']
|
||||
|
||||
@@ -84,6 +84,19 @@ def test_theme_scope_comma_at_beginning_and_end():
|
||||
assert theme.select(('b',)).i is True
|
||||
|
||||
|
||||
def test_theme_scope_internal_newline_commas():
|
||||
# this is arguably malformed, but `cobalt2` in the wild has this issue
|
||||
theme = Theme.from_dct({
|
||||
'colors': {'foreground': '#cccccc', 'background': '#333333'},
|
||||
'tokenColors': [
|
||||
{'scope': '\n,a,\n,b,\n', 'settings': {'fontStyle': 'italic'}},
|
||||
],
|
||||
})
|
||||
assert theme.select(('d',)).i is False
|
||||
assert theme.select(('a',)).i is True
|
||||
assert theme.select(('b',)).i is True
|
||||
|
||||
|
||||
def test_theme_scope_as_A_list():
|
||||
theme = Theme.from_dct({
|
||||
'colors': {'foreground': '#cccccc', 'background': '#333333'},
|
||||
|
||||
Reference in New Issue
Block a user