@@ -53,7 +53,7 @@ def process_event(self, e):
53
53
assert self .has_focus
54
54
if isinstance (e , events .PasteEvent ):
55
55
for ee in e .events :
56
- self .add_normal_character (ee if len ( ee ) == 1 else ee [ - 1 ]) #strip control seq
56
+ self .add_normal_character (ee )
57
57
elif e in rl_char_sequences :
58
58
self .cursor_offset_in_line , self .current_line = rl_char_sequences [e ](self .cursor_offset_in_line , self .current_line )
59
59
elif isinstance (e , events .SigIntEvent ):
@@ -79,6 +79,8 @@ def process_event(self, e):
79
79
self .repl .send_to_stdin (self .current_line )
80
80
81
81
def add_normal_character (self , e ):
82
+ if len (e ) > 1 or is_nop (e ):
83
+ return
82
84
logging .debug ('adding normal char %r to current line' , e )
83
85
c = e if py3 else e .encode ('utf8' )
84
86
self .current_line = (self .current_line [:self .cursor_offset_in_line ] +
@@ -350,7 +352,7 @@ def process_event(self, e):
350
352
elif e in ["\x1b " ]: #ESC
351
353
pass
352
354
else :
353
- self .add_normal_character (e if len ( e ) == 1 else e [ - 1 ]) #strip control seq
355
+ self .add_normal_character (e )
354
356
self .update_completion ()
355
357
356
358
def on_enter (self , insert_into_history = True ):
@@ -424,8 +426,7 @@ def process_simple_event(self, e):
424
426
elif isinstance (e , events .Event ):
425
427
pass # ignore events
426
428
else :
427
- if len (e ) == 1 :
428
- self .add_normal_character (e if len (e ) == 1 else e [- 1 ]) #strip control seq
429
+ self .add_normal_character (e )
429
430
430
431
def send_current_block_to_external_editor (self , filename = None ):
431
432
text = self .send_to_external_editor (self .get_current_block ())
@@ -453,8 +454,7 @@ def send_session_to_external_editor(self, filename=None):
453
454
454
455
## Handler Helpers
455
456
def add_normal_character (self , char ):
456
- assert len (char ) == 1 , repr (char )
457
- if is_nop (char ):
457
+ if len (char ) > 1 or is_nop (char ):
458
458
return
459
459
self ._current_line = (self ._current_line [:self .cursor_offset_in_line ] +
460
460
char +
@@ -942,7 +942,7 @@ def getstdout(self):
942
942
return s
943
943
944
944
def is_nop (char ):
945
- return unicodedata .category (char ) == 'Cc'
945
+ return unicodedata .category (unicode ( char ) ) == 'Cc'
946
946
947
947
def compress_paste_event (paste_event ):
948
948
"""If all events in a paste event are identical and not simple characters, returns one of them
0 commit comments