X Tutup
Skip to content

Commit 5af256d

Browse files
Corrected a bug in handling of ^N and ^P with stripspaces on.
1 parent 5750017 commit 5af256d

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

Lib/curses/textpad.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ class Textbox:
2020
Ctrl-A Go to left edge of window.
2121
Ctrl-B Cursor left, wrapping to previous line if appropriate.
2222
Ctrl-D Delete character under cursor.
23-
Ctrl-E Go to right edge (nospaces off) or end of line (nospaces on).
23+
Ctrl-E Go to right edge (stripspaces off) or end of line (stripspaces on).
2424
Ctrl-F Cursor right, wrapping to next line when appropriate.
2525
Ctrl-G Terminate, returning the window contents.
2626
Ctrl-H Delete character backward.
2727
Ctrl-J Terminate if the window is 1 line, otherwise insert newline.
2828
Ctrl-K If line is blank, delete it, otherwise clear to end of line.
29-
Ctrl-L Refresh screen
29+
Ctrl-L Refresh screen.
3030
Ctrl-N Cursor down; move down one line.
3131
Ctrl-O Insert a blank line at cursor location.
3232
Ctrl-P Cursor up; move up one line.
@@ -46,7 +46,7 @@ def __init__(self, win):
4646
self.lastcmd = None
4747
win.keypad(1)
4848

49-
def firstblank(self, y):
49+
def _end_of_line(self, y):
5050
"Go to the location of the first blank on the given line."
5151
last = self.maxx
5252
while 1:
@@ -79,7 +79,7 @@ def do_command(self, ch):
7979
elif y == 0:
8080
pass
8181
elif self.stripspaces:
82-
self.win.move(y-1, self.firstblank(y-1))
82+
self.win.move(y-1, self._end_of_line(y-1))
8383
else:
8484
self.win.move(y-1, self.maxx)
8585
if ch in (ascii.BS, curses.KEY_BACKSPACE):
@@ -88,7 +88,7 @@ def do_command(self, ch):
8888
self.win.delch()
8989
elif ch == ascii.ENQ: # ^e
9090
if self.stripspaces:
91-
self.win.move(y, self.firstblank(y))
91+
self.win.move(y, self._end_of_line(y))
9292
else:
9393
self.win.move(y, self.maxx)
9494
elif ch in (ascii.ACK, curses.KEY_RIGHT): # ^f
@@ -106,7 +106,7 @@ def do_command(self, ch):
106106
elif y < self.maxy:
107107
self.win.move(y+1, 0)
108108
elif ch == ascii.VT: # ^k
109-
if x == 0 and self.firstblank(y) == 0:
109+
if x == 0 and self._end_of_line(y) == 0:
110110
self.win.deleteln()
111111
else:
112112
self.win.clrtoeol()
@@ -115,20 +115,24 @@ def do_command(self, ch):
115115
elif ch in (ascii.SO, curses.KEY_DOWN): # ^n
116116
if y < self.maxy:
117117
self.win.move(y+1, x)
118+
if x > self._end_of_line(y+1):
119+
self.win.move(y+1, self._end_of_line(y+1))
118120
elif ch == ascii.SI: # ^o
119121
self.win.insertln()
120122
elif ch in (ascii.DLE, curses.KEY_UP): # ^p
121123
if y > 0:
122124
self.win.move(y-1, x)
125+
if x > self._end_of_line(y-1):
126+
self.win.move(y-1, self._end_of_line(y-1))
123127
return 1
124128

125129
def gather(self):
126130
"Collect and return the contents of the window."
127131
result = ""
128132
for y in range(self.maxy+1):
129133
self.win.move(y, 0)
130-
stop = self.firstblank(y)
131-
#sys.stderr.write("y=%d, firstblank(y)=%d\n" % (y, stop))
134+
stop = self._end_of_line(y)
135+
#sys.stderr.write("y=%d, _end_of_line(y)=%d\n" % (y, stop))
132136
if stop == 0 and self.stripspaces:
133137
continue
134138
for x in range(self.maxx+1):

0 commit comments

Comments
 (0)
X Tutup