6
6
from .plugin .settings import load_settings , settings , unload_settings
7
7
8
8
NAME = "Colored Comments"
9
- VERSION = "3.0.1 "
9
+ VERSION = "3.0.2 "
10
10
11
- region_keys = list ()
12
11
color_scheme_manager = ColorManager
13
-
14
12
comment_selector = "comment - punctuation.definition.comment"
15
13
16
14
@@ -28,17 +26,17 @@ def on_modified_async(self, view):
28
26
29
27
class ColoredCommentsCommand (sublime_plugin .TextCommand ):
30
28
def run (self , edit ):
31
- if self .view .match_selector ( 0 , "text.plain" ) :
29
+ if self .view .settings (). get ( "syntax" ) in settings . disabled_syntax :
32
30
return
33
31
34
32
self .ClearDecorations ()
35
33
self .ApplyDecorations ()
36
34
37
- def ClearDecorations (self ):
38
- for region_key in region_keys :
35
+ def ClearDecorations (self ) -> None :
36
+ for region_key in settings . region_keys :
39
37
self .view .erase_regions (region_key )
40
38
41
- def ApplyDecorations (self ):
39
+ def ApplyDecorations (self ) -> None :
42
40
to_decorate = dict ()
43
41
prev_match = str ()
44
42
for region in self .view .find_by_selector (comment_selector ):
@@ -72,10 +70,10 @@ def ApplyDecorations(self):
72
70
regions = to_decorate .get (key ),
73
71
scope = _get_scope_for_region (tag ),
74
72
icon = settings .comment_icon if settings .comment_icon_enabled else "" ,
75
- flags = self ._get_tag_flags (tag ),
73
+ flags = self ._get_flags (tag ),
76
74
)
77
75
78
- def _get_tag_flags (self , tag ) :
76
+ def _get_flags (self , tag : dict ) -> int :
79
77
options = {
80
78
"outline" : sublime .DRAW_NO_FILL ,
81
79
"underline" : sublime .DRAW_SOLID_UNDERLINE ,
@@ -84,11 +82,16 @@ def _get_tag_flags(self, tag):
84
82
}
85
83
flags = sublime .PERSISTENT
86
84
for index , option in options .items ():
87
- if index in tag .keys () and tag [ index ] is True :
85
+ if tag .get ( index ) is True :
88
86
flags |= option
89
87
return flags
90
88
91
89
90
+ class ColoredCommentsClearCommand (ColoredCommentsCommand , sublime_plugin .TextCommand ):
91
+ def run (self , edit ):
92
+ self .ClearDecorations ()
93
+
94
+
92
95
class ColoredCommentsThemeGeneratorCommand (sublime_plugin .TextCommand ):
93
96
def run (self , edit ):
94
97
color_scheme_manager .tags = settings .tags
@@ -99,35 +102,24 @@ class ColoredCommentsThemeRevertCommand(sublime_plugin.TextCommand):
99
102
def run (self , edit ):
100
103
preferences = sublime .load_settings ("Preferences.sublime-settings" )
101
104
if preferences .get ("color_scheme" ):
102
- color_scheme_manager .remove_override (
103
- preferences .get ("color_scheme" ))
105
+ color_scheme_manager .remove_override (preferences .get ("color_scheme" ))
104
106
105
107
106
108
def _get_scope_for_region (tag : dict ) -> str :
107
109
if tag .get ("scope" ):
108
110
return tag .get ("scope" )
109
- scope_name = "colored.comments.color.{}" .format (
110
- tag .get ("color" ).get ("name" ))
111
+ scope_name = "colored.comments.color.{}" .format (tag .get ("color" ).get ("name" ))
111
112
return scope_name .replace (" " , "." ).lower ()
112
113
113
114
114
- def _generate_region_keys (region_keys , tag_map ):
115
- for key in tag_map :
116
- if key .lower () not in region_keys :
117
- region_keys .append (key .lower ())
118
-
119
-
120
- def plugin_loaded ():
115
+ def plugin_loaded () -> None :
121
116
global region_keys
122
117
global color_scheme_manager
123
118
load_settings ()
124
- _generate_region_keys (region_keys , settings .tags )
125
119
log .set_debug_logging (settings .debug )
126
120
127
- color_scheme_manager = ColorManager (
128
- tags = settings .tags
129
- )
121
+ color_scheme_manager = ColorManager (tags = settings .tags )
130
122
131
123
132
- def plugin_unloaded ():
124
+ def plugin_unloaded () -> None :
133
125
unload_settings ()
0 commit comments