diff --git a/babi/theme.py b/babi/theme.py index 1982428..ce112f0 100644 --- a/babi/theme.py +++ b/babi/theme.py @@ -116,8 +116,9 @@ class Theme(NamedTuple): scopes = [''] elif isinstance(rule['scope'], str): scopes = [ - # some themes have a buggy trailing comma - s.strip() for s in rule['scope'].strip(',').split(',') + s.strip() + # some themes have a buggy trailing/leading comma + for s in rule['scope'].strip().strip(',').split(',') ] else: scopes = rule['scope'] diff --git a/tests/theme_test.py b/tests/theme_test.py index 4c7cae0..a4a1d8d 100644 --- a/tests/theme_test.py +++ b/tests/theme_test.py @@ -72,6 +72,18 @@ def test_theme_scope_split_by_commas(): assert theme.select(('c',)).i is True +def test_theme_scope_comma_at_beginning_and_end(): + theme = Theme.from_dct({ + 'colors': {'foreground': '#cccccc', 'background': '#333333'}, + 'tokenColors': [ + {'scope': '\n,a,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'},