@@ -107,22 +107,22 @@ def show_inline_blame(self):
107
107
return
108
108
109
109
phantoms = []
110
- sels = self .view .sel ()
111
- if len (sels ) < 1 :
112
- return
113
110
111
+ sels = self .view .sel ()
114
112
# @todo Support showing inline blame for multiple carets?
115
113
# @body Maybe with a sanity check that there aren't too many (more than 10?)
116
- line = self .view .line (sels [0 ])
117
- if line .size () < 2 :
118
- # avoid weird behaviour of regions on empty lines
119
- # < 2 is to check for newline character
114
+ if len (sels ) != 1 :
120
115
return
121
- pos = line .end ()
122
- row , _ = self .view .rowcol (line .begin ())
123
- anchor = sublime .Region (pos , pos )
116
+ sel0 = sels [0 ]
117
+
118
+ phantom_pos , caret_line_num = self .calculate_positions (sel0 )
119
+ if not phantom_pos :
120
+ return
121
+
124
122
try :
125
- blame_output = self .get_blame_text (self .view .file_name (), line_num = row + 1 )
123
+ blame_output = self .get_blame_text (
124
+ self .view .file_name (), line_num = caret_line_num
125
+ )
126
126
except Exception :
127
127
return
128
128
blame = next (
@@ -152,13 +152,37 @@ def show_inline_blame(self):
152
152
summary = summary ,
153
153
)
154
154
phantom = sublime .Phantom (
155
- anchor , body , sublime .LAYOUT_INLINE , self .handle_phantom_button
155
+ sublime .Region (phantom_pos ),
156
+ body ,
157
+ sublime .LAYOUT_INLINE ,
158
+ self .handle_phantom_button ,
156
159
)
157
160
phantoms .append (phantom )
158
161
159
162
# Dispatch back onto the main thread to serialize a final is_dirty check.
160
163
sublime .set_timeout (lambda : self .maybe_insert_phantoms (phantoms ), 0 )
161
164
165
+ def calculate_positions (self , user_selection ):
166
+ selection_goes_backwards = user_selection .a > user_selection .b
167
+
168
+ row , _ = self .view .rowcol (
169
+ user_selection .begin () if selection_goes_backwards else user_selection .end ()
170
+ )
171
+ caret_line_num = row + 1
172
+
173
+ # Quantise the arbitrary user selection to line(s)
174
+ selection = self .view .line (user_selection )
175
+ if selection .size () <= 1 :
176
+ # Not worth showing a blame phantom for an empty line.
177
+ return (None , caret_line_num )
178
+
179
+ if selection_goes_backwards :
180
+ phantom_pos = self .view .line (selection .begin ()).end ()
181
+ else :
182
+ phantom_pos = selection .end ()
183
+
184
+ return (phantom_pos , caret_line_num )
185
+
162
186
def maybe_insert_phantoms (self , phantoms ):
163
187
if not self .view .is_dirty ():
164
188
self .phantom_set .update (phantoms )
0 commit comments