textbox: fix right-key going banana

This commit is contained in:
dece 2021-05-16 19:42:05 +02:00
parent 1ae2ed41e5
commit 0a746a1e28

View file

@ -10,11 +10,11 @@ All Rights Reserved
This version fixes a few quirks of the standard module, namely: This version fixes a few quirks of the standard module, namely:
- Discard multi-lines mode: only one line is supported. - Discard multi-lines mode: only one line is supported.
- Moving in line more reasonably: no more going alone rightward.
""" """
import curses import curses
import curses.ascii import curses.ascii
import logging
class Textbox: class Textbox:
@ -51,7 +51,6 @@ class Textbox:
def _end_of_line(self): def _end_of_line(self):
"""Return the index of the last non-blank character.""" """Return the index of the last non-blank character."""
logging.debug(f"textpad._end_of_line")
self._update_maxx() self._update_maxx()
last = self.maxx last = self.maxx
while True: while True:
@ -65,7 +64,6 @@ class Textbox:
return last return last
def _insert_printable_char(self, ch): def _insert_printable_char(self, ch):
logging.debug(f"textpad._insert_printable_char {ch}")
self._update_maxx() self._update_maxx()
_, x = self.win.getyx() _, x = self.win.getyx()
backx = None backx = None
@ -93,7 +91,6 @@ class Textbox:
def do_command(self, ch): def do_command(self, ch):
"""Process a single editing command.""" """Process a single editing command."""
logging.debug(f"textpad.do_command {ch}")
self._update_maxx() self._update_maxx()
_, x = self.win.getyx() _, x = self.win.getyx()
if curses.ascii.isprint(ch): if curses.ascii.isprint(ch):
@ -122,7 +119,7 @@ class Textbox:
self.win.move(0, self.maxx) self.win.move(0, self.maxx)
elif ch in (curses.ascii.ACK, curses.KEY_RIGHT): # ^f elif ch in (curses.ascii.ACK, curses.KEY_RIGHT): # ^f
if x < self.maxx: if x < self.maxx:
self.win.move(0, x + 1) self.win.move(0, min(x + 1, self._end_of_line()))
elif ch == curses.ascii.VT: # ^k elif ch == curses.ascii.VT: # ^k
if x == 0 and self._end_of_line() == 0: if x == 0 and self._end_of_line() == 0:
self.win.deleteln() self.win.deleteln()