commit 2b17ec2b8c287a1268790da54e5f5ba32281a315 Author: Damian Johnson atagar@torproject.org Date: Sat Jul 23 09:36:13 2016 -0700
Tab completion always moved cursor to end
Curses' gather() method moves the cursor to the end of the message. As such whenever we call gather() we need to revert the cursor position afterward. Here's the repro steps for the issue...
* in the interpreter panel type 'hello' * moved the cursor to the middle of the word * press tab, the cursor will move to the end of the line
This was a bug copied from the arm 1.4.5 release (it was there too). --- nyx/curses.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/nyx/curses.py b/nyx/curses.py index 0cf9527..ecc2644 100644 --- a/nyx/curses.py +++ b/nyx/curses.py @@ -303,7 +303,7 @@ def str_input(x, y, initial_text = '', backlog = None, tab_completion = None):
def _handle_key(textbox, key): """ - Handles esc, home, end, right arrow, and resizing. We don't need ot handle + Handles esc, home, end, right arrow, and resizing. We don't need to handle the left arrow key because curses has reasonable behavior for that one.
:param Textbox textbox: current textbox context @@ -322,7 +322,7 @@ def _handle_key(textbox, key): msg_length = len(textbox.gather()) textbox.win.move(y, x) # reverts cursor movement during gather call
- if key == curses.KEY_END and msg_length > 0 and x < msg_length - 1: + if key == curses.KEY_END and x < msg_length - 1: textbox.win.move(y, msg_length - 1) # if we're in the content then move to the end elif key == curses.KEY_RIGHT and x < msg_length - 1: textbox.win.move(y, x + 1) # only move cursor if there's content after it @@ -393,9 +393,12 @@ def _handle_tab_completion(next_handler, tab_completion, textbox, key): """
if key == 9: + y, x = textbox.win.getyx() current_contents = textbox.gather().strip() - matches = tab_completion(current_contents) + textbox.win.move(y, x) # reverts cursor movement during gather call + new_input = None + matches = tab_completion(current_contents)
if len(matches) == 1: new_input = matches[0] @@ -406,7 +409,6 @@ def _handle_tab_completion(next_handler, tab_completion, textbox, key): new_input = common_prefix
if new_input: - y, _ = textbox.win.getyx() _, max_x = textbox.win.getmaxyx() textbox.win.clear() textbox.win.addstr(y, 0, new_input[:max_x - 1])
tor-commits@lists.torproject.org