editor: Ring bell when trying to move cursor out of bounds.

- At the start or end of file.
This commit is contained in:
Andrew Hamilton 2022-01-13 14:34:47 +10:00
parent 8b24095d63
commit ac340dd0ca

View file

@ -541,10 +541,7 @@ class Editor:
print("\a", end="")
def undo(self):
try:
self.text_widget[:], self._cursor_x, self._cursor_y = self.history.pop()
except IndexError:
self.ring_bell()
self.text_widget[:], self._cursor_x, self._cursor_y = self.history.pop()
def abort_command(self):
self.mark = None
@ -578,8 +575,10 @@ class Editor:
if term_code != terminal.CTRL_UNDERSCORE:
self.add_to_history()
if term_code in Editor.KEY_MAP:
with contextlib.suppress(IndexError):
try:
Editor.KEY_MAP[term_code](self)
except IndexError:
self.ring_bell()
elif term_code in self._PRINTABLE:
self.insert_text(term_code)
else: