@@ -46,6 +46,14 @@ def count_lines_with_wrapping(s, linewidth=80, tabwidth=8):
4646
4747 # deal with tab or newline
4848 if s [pos ] == '\n ' :
49+ # Avoid the `current_column == 0` edge-case, and while we're at it,
50+ # don't bother adding 0.
51+ if current_column > linewidth :
52+ # If the current column was exactly linewidth, divmod would give
53+ # (1,0), even though a new line hadn't yet been started. The same
54+ # is true if length is any exact multiple of linewidth. Therefore,
55+ # subtract 1 before dividing a non-empty line.
56+ linecount += (current_column - 1 ) // linewidth
4957 linecount += 1
5058 current_column = 0
5159 else :
@@ -60,17 +68,6 @@ def count_lines_with_wrapping(s, linewidth=80, tabwidth=8):
6068
6169 pos += 1 # after the tab or newline
6270
63- # avoid divmod(-1, linewidth)
64- if current_column > 0 :
65- # If the length was exactly linewidth, divmod would give (1,0),
66- # even though a new line hadn't yet been started. The same is true
67- # if length is any exact multiple of linewidth. Therefore, subtract
68- # 1 before doing divmod, and later add 1 to the column to
69- # compensate.
70- lines , column = divmod (current_column - 1 , linewidth )
71- linecount += lines
72- current_column = column + 1
73-
7471 # process remaining chars (no more tabs or newlines)
7572 current_column += len (s ) - pos
7673 # avoid divmod(-1, linewidth)
@@ -106,7 +103,8 @@ def __init__(self, s, tags, numoflines, squeezer):
106103 # before the iomark
107104 self .base_text = editwin .per .bottom
108105
109- button_text = "Squeezed text (%d lines)." % self .numoflines
106+ line_plurality = "lines" if numoflines != 1 else "line"
107+ button_text = f"Squeezed text ({ numoflines } { line_plurality } )."
110108 tk .Button .__init__ (self , text , text = button_text ,
111109 background = "#FFFFC0" , activebackground = "#FFFFE0" )
112110
0 commit comments