@@ -160,16 +160,16 @@ def run(self, edit, **kwargs):
160160
161161
162162class FileDiffSelectionsCommand (FileDiffCommand ):
163- def run (self , edit , ** kwargs ):
164- regions = self .view .sel ()
165- current = self .view .substr (regions [0 ])
166- diff = self .view .substr (regions [1 ])
167-
168- # trim off indent
163+ def trim_indent (self , lines ):
169164 indent = None
170- for line in current .splitlines ():
165+ for line in lines :
166+ # ignore blank lines
167+ if line == '' :
168+ continue
169+
171170 new_indent = re .match ('[ \t ]*' , line ).group (0 )
172- if new_indent == '' :
171+ # ignore lines that only consist of whitespace
172+ if len (new_indent ) == len (line ):
173173 continue
174174
175175 if indent is None :
@@ -179,26 +179,24 @@ def run(self, edit, **kwargs):
179179
180180 if not indent :
181181 break
182+ return indent
182183
183- if indent :
184- current = u"\n " .join (line [len (indent ):] for line in current .splitlines ())
184+ def run (self , edit , ** kwargs ):
185+ regions = self .view .sel ()
186+ first_selection = self .view .substr (regions [0 ])
187+ second_selection = self .view .substr (regions [1 ])
185188
186189 # trim off indent
187- indent = None
188- for line in diff .splitlines ():
189- new_indent = re .match ('[ \t ]*' , line ).group (0 )
190- if new_indent == '' :
191- continue
192-
193- if indent is None :
194- indent = new_indent
195- elif len (new_indent ) < len (indent ):
196- indent = new_indent
190+ indent = self .trim_indent (first_selection .splitlines ())
191+ if indent :
192+ first_selection = u"\n " .join (line [len (indent ):] for line in first_selection .splitlines ())
197193
194+ # trim off indent
195+ indent = self .trim_indent (second_selection .splitlines ())
198196 if indent :
199- diff = u"\n " .join (line [len (indent ):] for line in diff .splitlines ())
197+ second_selection = u"\n " .join (line [len (indent ):] for line in second_selection .splitlines ())
200198
201- self .run_diff (current , diff ,
199+ self .run_diff (first_selection , second_selection ,
202200 from_file = 'first selection' ,
203201 to_file = 'second selection' ,
204202 external_diff_tool = kwargs .get ('cmd' , None ))
0 commit comments