@@ -336,8 +336,7 @@ def recenterHeadings(self):
336336 if self .allLines [i ].isHeading :
337337 break
338338 lineLength = self .allLines [i ].textLocation
339- if lineLength > maxLineLength :
340- maxLineLength = lineLength
339+ maxLineLength = max (maxLineLength , lineLength )
341340 for j in range (indexStart , indexFinal ):
342341 brailleTextLine = self .allLines [j ]
343342 lineStrToCenter = str (brailleTextLine )
@@ -565,12 +564,10 @@ def insert(self, textLocation, text):
565564 '''
566565 if not self .canInsert (textLocation , text ):
567566 raise BrailleTextException ('Text cannot be inserted at specified location.' )
568- self .textLocation = textLocation
569- for char in list (text ):
570- self .allChars [self .textLocation ] = char
571- self .textLocation += 1
572- if self .textLocation > self .highestUsedLocation :
573- self .highestUsedLocation = self .textLocation
567+ for i , char in enumerate (text , start = textLocation ):
568+ self .allChars [i ] = char
569+ self .textLocation = textLocation + len (text )
570+ self .highestUsedLocation = max (self .highestUsedLocation , self .textLocation )
574571
575572 def canAppend (self , text , addSpace = True ):
576573 '''
@@ -600,10 +597,7 @@ def canAppend(self, text, addSpace=True):
600597 >>> btl.canAppend('1234', addSpace=False)
601598 False
602599 '''
603- if self .highestUsedLocation > self .textLocation :
604- searchLocation = self .highestUsedLocation
605- else :
606- searchLocation = self .textLocation
600+ searchLocation = max (self .highestUsedLocation , self .textLocation )
607601 addSpaceAmount = 1 if addSpace else 0
608602 if (searchLocation + len (text ) + addSpaceAmount ) > self .lineLength :
609603 return False
0 commit comments