summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lepus.uberspace.de>2014-10-15 21:20:59 +0200
committerhut <hut@lepus.uberspace.de>2014-10-15 21:21:30 +0200
commit6721127a497595fbdc0d237c4c1021fcd783ee41 (patch)
tree078adbaaa898e504f5b5a8a341881e86a49a7b46 /ranger
parent74a4dde385d23e091a21e39b5d779f3169b846ab (diff)
downloadranger-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.py27
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
d'>ce5bf721 ^
a0d5c07a ^
81b5230d ^


25922160 ^


66f9a6b7 ^




1bbb819d ^



815a6557 ^
1bbb819d ^

e3797076 ^


1bbb819d ^


d1bf922b ^


815a6557 ^
d1bf922b ^











951df64a ^

d15f905d ^





25922160 ^














02e7cc02 ^



46c8245a ^
ce5bf721 ^

a9c875e2 ^




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132