11
11
12
12
13
13
class UroborosqlFormatCommand (sublime_plugin .TextCommand ):
14
- """SQL Format Command class"""
14
+
15
+ """SQL format command class"""
15
16
16
17
def run (self , edit ):
17
18
view = self .view
19
+ view .window ().status_message ('formatting...' )
18
20
self .settings = view .settings ()
19
21
self .user_settings = sublime .load_settings (
20
22
'sublime-uroborosql-formatter.sublime-settings' )
21
- regions = view .sel ()
22
23
# set syntax
23
24
if self .settings .get ('syntax' ) == \
24
25
"Packages/Text/Plain text.tmLanguage" :
@@ -30,13 +31,13 @@ def run(self, edit):
30
31
31
32
config = LocalConfig ()
32
33
config .set_uppercase (self .getval ("uf_uppercase" ))
33
- uroborosqlfmt .config .glb .escape_sequence_u005c = self .getval ("uf_escapesequence_u005c" )
34
+ uroborosqlfmt .config .glb .escape_sequence_u005c = self .getval (
35
+ "uf_escapesequence_u005c" )
34
36
if str (self .getval ("uf_comment_syntax" )).upper () == "DOMA2" :
35
37
config .set_commentsyntax (Doma2CommentSyntax ())
36
38
37
39
raw_text = ""
38
- region = None
39
-
40
+ regions = view .sel ()
40
41
# format selection
41
42
if len (regions ) > 1 or not regions [0 ].empty ():
42
43
for region in view .sel ():
@@ -46,26 +47,27 @@ def run(self, edit):
46
47
region = sublime .Region (0 , view .size ())
47
48
raw_text = view .substr (region )
48
49
49
- threading .Thread (target = self .run_format , args = (edit , raw_text , region , config , )).start ()
50
+ threading .Thread (target = self .run_format , args = (
51
+ edit , raw_text , config , region .a , region .b )).start ()
50
52
51
- def run_format (self , edit , raw_text , region , config ):
53
+ def run_format (self , edit , raw_text , config , region_a , region_b ):
52
54
formatted_text = uroborosqlfmt .format_sql (raw_text , config )
53
- self .view .run_command ("uroborosql_format_view" , {"formatted_text" : formatted_text })
55
+ self .view .run_command ("uroborosql_format_replace" , {
56
+ "region_a" : region_a ,
57
+ "region_b" : region_b ,
58
+ "formatted_text" : formatted_text
59
+ })
54
60
55
61
def getval (self , key ):
56
62
val = self .user_settings .get (key )
57
63
return val if val != None else self .settings .get (key )
58
64
59
65
60
- class UroborosqlFormatViewCommand (sublime_plugin .TextCommand ):
61
- def run (self , edit , ** args ):
62
- regions = self .view .sel ()
63
- # format selection
64
- if len (regions ) > 1 or not regions [0 ].empty ():
65
- for region in self .view .sel ():
66
- if not region .empty ():
67
- break
68
- else : # format all
69
- region = sublime .Region (0 , self .view .size ())
66
+ class UroborosqlFormatReplaceCommand (sublime_plugin .TextCommand ):
70
67
68
+ """SQL format replace command class"""
69
+
70
+ def run (self , edit , ** args ):
71
+ region = sublime .Region (args ["region_a" ], args ["region_b" ])
71
72
self .view .replace (edit , region , args ["formatted_text" ])
73
+ self .view .window ().status_message ('formatting... complete!!' )
0 commit comments