Skip to content

Commit 5c8418d

Browse files
committed
Read the whole line and strip the redundant blanks
in_wstr() reads a line to its end, so gather() no longer needs move() + _end_of_line() to work out how much of it to ask for: strip the trailing blanks instead, keeping the one the cursor rests on.
1 parent 61dffa7 commit 5c8418d

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

Lib/curses/textpad.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,16 @@ def gather(self):
200200
result = ""
201201
self._update_max_yx()
202202
for y in range(self.maxy+1):
203-
self.win.move(y, 0)
204-
stop = self._end_of_line(y)
205-
if stop == 0 and self.stripspaces:
206-
continue
207-
count = stop+1 if self.stripspaces else self.maxx+1
208-
result = result + str(self.win.in_wchstr(y, 0, count))
203+
# The whole line: in_wstr() reads a double-width character once,
204+
# skipping the continuation cell that holds its other half.
205+
line = self.win.in_wstr(y, 0)
206+
if self.stripspaces:
207+
stripped = line.rstrip(' ')
208+
if not stripped:
209+
continue
210+
# Keep the blank the cursor rests on past the last character.
211+
line = stripped + ' ' if len(stripped) < len(line) else stripped
212+
result = result + line
209213
if self.maxy > 0:
210214
result = result + "\n"
211215
return result

0 commit comments

Comments
 (0)