[tor-commits] [nyx/master] Implement delete key

atagar at torproject.org atagar at torproject.org
Thu Jan 10 23:08:03 UTC 2019


commit 321eb30eb1f38eb16b94ead67ad21cf5e3930a48
Author: Damian Johnson <atagar at torproject.org>
Date:   Wed Jan 9 11:35:00 2019 -0800

    Implement delete key
    
    Special keys (arrows, home/end, etc) require for us to implement their
    handling. Doing so for the delete key.
    
      https://trac.torproject.org/projects/tor/ticket/5835
---
 nyx/curses.py            | 12 ++++++++++++
 web/changelog/index.html |  1 +
 2 files changed, 13 insertions(+)

diff --git a/nyx/curses.py b/nyx/curses.py
index 3f4b797..9f998b0 100644
--- a/nyx/curses.py
+++ b/nyx/curses.py
@@ -318,6 +318,18 @@ def _handle_key(textbox, key):
       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
+  elif key == curses.KEY_DC:
+    # Delete key. Remove the character after the cursor if there is one.
+
+    y, x = textbox.win.getyx()
+    content = textbox.gather()
+
+    if x < len(content):
+      content = content[:x] + content[x + 1:]
+      textbox.win.clear()
+      textbox.win.addstr(y, 0, content)
+
+    textbox.win.move(y, x)  # revert cursor to its prior position
   elif key == 410:
     # if we're resizing the display during text entry then cancel it
     # (otherwise the input field is filled with nonprintable characters)
diff --git a/web/changelog/index.html b/web/changelog/index.html
index d49533e..dfb6465 100644
--- a/web/changelog/index.html
+++ b/web/changelog/index.html
@@ -126,6 +126,7 @@
         <li><span class="component">Curses</span>
           <ul>
             <li>Resizing could crash the interface (<b><a href="https://trac.torproject.org/projects/tor/ticket/24382">ticket</a></b>)</li>
+            <li>Implemented <b>del key</b> in editable text fields (<b><a href="https://trac.torproject.org/projects/tor/ticket/5835">ticket</a></b>)</li>
           </ul>
         </li>
 





More information about the tor-commits mailing list