Skip to content

Commit

Permalink
Let up/down arrows move focus out of edit box
Browse files Browse the repository at this point in the history
  • Loading branch information
danschwarz committed Feb 25, 2024
1 parent 5820f92 commit 88aedc7
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions urwid_readline/readline_edit.py
Expand Up @@ -115,10 +115,6 @@ def __init__(
if self.multiline:
self.keymap.update(
{
"up": self.previous_line,
"ctrl p": self.previous_line,
"ctrl n": self.next_line,
"down": self.next_line,
"enter": self.insert_new_line,
}
)
Expand All @@ -140,6 +136,12 @@ def keypress(self, size, key):
if key == "left":
return None if self.backward_char() else key

if key == "up" or key == "ctrl p":
return None if self.previous_line() else key

if key == "down" or key == "ctrl n":
return None if self.next_line() else key

if key in self.keymap:
if self.keymap[key] == self.undo:
self.keymap[key]()
Expand Down Expand Up @@ -210,11 +212,11 @@ def paste(self):

def previous_line(self):
x, y = self.get_cursor_coords(self.size)
self.move_cursor_to_coords(self.size, x, max(0, y - 1))
return self.move_cursor_to_coords(self.size, x, max(0, y - 1))

def next_line(self):
x, y = self.get_cursor_coords(self.size)
self.move_cursor_to_coords(self.size, x, y + 1)
return self.move_cursor_to_coords(self.size, x, y + 1)

def backward_char(self):
if self._edit_pos > 0:
Expand Down

0 comments on commit 88aedc7

Please sign in to comment.