@@ -91,9 +91,6 @@ def paint_line_numbers(self, line_numbers, event):
9191 height = font_metrics .height ()
9292 width = line_numbers .width ()
9393
94- cursor = self .document_contents .textCursor ()
95- current_line_number = cursor .blockNumber () + 1
96-
9794 while block .isValid ():
9895 # blocks are numbered from zero
9996 line_number += 1
@@ -116,7 +113,7 @@ def paint_line_numbers(self, line_numbers, event):
116113 if self .document_contents .block_has_breakpoint (block ):
117114 brush = painter .brush ()
118115 brush .setStyle (Qt .SolidPattern )
119- if line_number == current_line_number :
116+ if self . document_contents . block_is_current ( block ) :
120117 brush .setColor (Qt .red )
121118 else :
122119 brush .setColor (Qt .darkGreen )
@@ -136,8 +133,8 @@ def paint_line_numbers(self, line_numbers, event):
136133 def get_path (self ):
137134 return self .document_contents .document_model .path
138135
139- def move_to_line (self , line ):
140- self .document_contents .move_to_line (line )
136+ def move_to_line (self , line , is_current = True ):
137+ self .document_contents .move_to_line (line , is_current )
141138 self .rehighlight_breakpoint_lines ()
142139
143140 def remove_line_highlights (self ):
@@ -219,7 +216,7 @@ def mouseDoubleClickEvent(self, event):
219216 def contextMenuEvent (self , event ):
220217 pass
221218
222- def move_to_line (self , line ):
219+ def move_to_line (self , line , is_current = True ):
223220 """Move cursor to line
224221
225222 Move the cursor of the QPlainTextEdit that holds the document
@@ -244,11 +241,19 @@ def move_to_line(self, line):
244241 1
245242 )
246243
244+ # Unmark block as current
245+ block = cursor .block ()
246+ self .block_set_is_current (block , False )
247+
247248 if cursor_moved is False :
248249 break
249250
250251 block_number = cursor .blockNumber ()
251252
253+ # Mark block on which the cursor is as the current on
254+ block = cursor .block ()
255+ self .block_set_is_current (block , is_current )
256+
252257 self .setTextCursor (cursor )
253258
254259 def highlight (self ):
@@ -288,6 +293,15 @@ def block_remove_breakpoint(self, block):
288293 user_data .breakpoint = False
289294 block .setUserData (user_data )
290295
296+ def block_is_current (self , block ):
297+ user_data = self .__get_block_user_data (block )
298+ return user_data .is_current
299+
300+ def block_set_is_current (self , block , is_current ):
301+ user_data = self .__get_block_user_data (block )
302+ user_data .is_current = is_current
303+ block .setUserData (user_data )
304+
291305 def __get_block_user_data (self , block ):
292306 user_data = block .userData ()
293307 if user_data is None :
@@ -317,6 +331,7 @@ def paintEvent(self, event):
317331class PugdebugBlockData (QTextBlockUserData ):
318332
319333 breakpoint = False
334+ is_current = False
320335
321336 def __init__ (self ):
322337 super (PugdebugBlockData , self ).__init__ ()
0 commit comments