diff options
author | hut <hut@lepus.uberspace.de> | 2014-10-15 21:20:59 +0200 |
---|---|---|
committer | hut <hut@lepus.uberspace.de> | 2014-10-15 21:21:30 +0200 |
commit | 6721127a497595fbdc0d237c4c1021fcd783ee41 (patch) | |
tree | 078adbaaa898e504f5b5a8a341881e86a49a7b46 /ranger | |
parent | 74a4dde385d23e091a21e39b5d779f3169b846ab (diff) | |
download | ranger-6721127a497595fbdc0d237c4c1021fcd783ee41.tar.gz |
gui.widgets.console: validate keys before adding to unicode_buffer
This, along with the previos commit, helps with a bug that GermainZ reported: If you press CTRL+Left Arrow when using ranger on python3, you become unable to type new letter keys because ranger tries to interpret all the input as a unicode sequence.
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/gui/widgets/console.py | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py index 597be9cd..8dd201e5 100644 --- a/ranger/gui/widgets/console.py +++ b/ranger/gui/widgets/console.py @@ -216,20 +216,21 @@ class Console(Widget): if self.fm.py3: if len(unicode_buffer) >= 4: unicode_buffer = "" - unicode_buffer += key - try: - decoded = unicode_buffer.encode("latin-1").decode("utf-8") - except UnicodeDecodeError: - return unicode_buffer, line, pos - except UnicodeEncodeError: - return unicode_buffer, line, pos - else: - unicode_buffer = "" - if pos == len(line): - line += decoded + if ord(key) in range(0, 256): + unicode_buffer += key + try: + decoded = unicode_buffer.encode("latin-1").decode("utf-8") + except UnicodeDecodeError: + return unicode_buffer, line, pos + except UnicodeEncodeError: + return unicode_buffer, line, pos else: - line = line[:pos] + decoded + line[pos:] - pos += len(decoded) + unicode_buffer = "" + if pos == len(line): + line += decoded + else: + line = line[:pos] + decoded + line[pos:] + pos += len(decoded) else: if pos == len(line): line += key |