@@ -122,58 +122,59 @@ def process_event(self, e: Union[events.Event, str]) -> None:
122122 assert self .has_focus
123123
124124 logger .debug ("fake input processing event %r" , e )
125- if isinstance (e , events .PasteEvent ):
126- for ee in e .events :
127- if ee not in self .rl_char_sequences :
128- self .add_input_character (ee )
129- elif e in self .rl_char_sequences :
130- self .cursor_offset , self .current_line = self .rl_char_sequences [e ](
131- self .cursor_offset , self .current_line
132- )
133- elif isinstance (e , events .SigIntEvent ):
134- self .coderunner .sigint_happened_in_main_context = True
135- self .has_focus = False
136- self .current_line = ""
137- self .cursor_offset = 0
138- self .repl .run_code_and_maybe_finish ()
139- elif e in ("<ESC>" ,):
140- pass
141- elif e in ("<Ctrl-d>" ,):
142- if self .current_line == "" :
143- self .repl .send_to_stdin ("\n " )
125+ if isinstance (e , events .Event ):
126+ if isinstance (e , events .PasteEvent ):
127+ for ee in e .events :
128+ if ee not in self .rl_char_sequences :
129+ self .add_input_character (ee )
130+ elif isinstance (e , events .SigIntEvent ):
131+ self .coderunner .sigint_happened_in_main_context = True
144132 self .has_focus = False
145133 self .current_line = ""
146134 self .cursor_offset = 0
147- self .repl .run_code_and_maybe_finish (for_code = "" )
148- else :
135+ self .repl .run_code_and_maybe_finish ()
136+ else :
137+ if e in self .rl_char_sequences :
138+ self .cursor_offset , self .current_line = self .rl_char_sequences [
139+ e
140+ ](self .cursor_offset , self .current_line )
141+ elif e in ("<ESC>" ,):
149142 pass
150- elif e in ("\n " , "\r " , "<Ctrl-j>" , "<Ctrl-m>" ):
151- line = self .current_line
152- self .repl .send_to_stdin (line + "\n " )
153- self .has_focus = False
154- self .current_line = ""
155- self .cursor_offset = 0
156- self .repl .run_code_and_maybe_finish (for_code = line + "\n " )
157- else : # add normal character
158- self .add_input_character (e )
143+ elif e in ("<Ctrl-d>" ,):
144+ if self .current_line == "" :
145+ self .repl .send_to_stdin ("\n " )
146+ self .has_focus = False
147+ self .current_line = ""
148+ self .cursor_offset = 0
149+ self .repl .run_code_and_maybe_finish (for_code = "" )
150+ else :
151+ pass
152+ elif e in ("\n " , "\r " , "<Ctrl-j>" , "<Ctrl-m>" ):
153+ line = self .current_line
154+ self .repl .send_to_stdin (line + "\n " )
155+ self .has_focus = False
156+ self .current_line = ""
157+ self .cursor_offset = 0
158+ self .repl .run_code_and_maybe_finish (for_code = line + "\n " )
159+ else : # add normal character
160+ self .add_input_character (e )
159161
160162 if self .current_line .endswith (("\n " , "\r " )):
161163 pass
162164 else :
163165 self .repl .send_to_stdin (self .current_line )
164166
165167 def add_input_character (self , e : str ) -> None :
166- if e in ( "<SPACE>" ,) :
168+ if e == "<SPACE>" :
167169 e = " "
168170 if e .startswith ("<" ) and e .endswith (">" ):
169171 return
170172 assert len (e ) == 1 , "added multiple characters: %r" % e
171173 logger .debug ("adding normal char %r to current line" , e )
172174
173- c = e
174175 self .current_line = (
175176 self .current_line [: self .cursor_offset ]
176- + c
177+ + e
177178 + self .current_line [self .cursor_offset :]
178179 )
179180 self .cursor_offset += 1
@@ -756,11 +757,11 @@ def process_key_event(self, e: str) -> None:
756757 self .up_one_line ()
757758 elif e in ("<DOWN>" ,) + key_dispatch [self .config .down_one_line_key ]:
758759 self .down_one_line ()
759- elif e in ( "<Ctrl-d>" ,) :
760+ elif e == "<Ctrl-d>" :
760761 self .on_control_d ()
761- elif e in ( "<Ctrl-o>" ,) :
762+ elif e == "<Ctrl-o>" :
762763 self .operate_and_get_next ()
763- elif e in ( "<Esc+.>" ,) :
764+ elif e == "<Esc+.>" :
764765 self .get_last_word ()
765766 elif e in key_dispatch [self .config .reverse_incremental_search_key ]:
766767 self .incremental_search (reverse = True )
@@ -796,9 +797,9 @@ def process_key_event(self, e: str) -> None:
796797 raise SystemExit ()
797798 elif e in ("\n " , "\r " , "<PADENTER>" , "<Ctrl-j>" , "<Ctrl-m>" ):
798799 self .on_enter ()
799- elif e in ( "<TAB>" ,) : # tab
800+ elif e == "<TAB>" : # tab
800801 self .on_tab ()
801- elif e in ( "<Shift-TAB>" ,) :
802+ elif e == "<Shift-TAB>" :
802803 self .on_tab (back = True )
803804 elif e in key_dispatch [self .config .undo_key ]: # ctrl-r for undo
804805 self .prompt_undo ()
@@ -817,9 +818,9 @@ def process_key_event(self, e: str) -> None:
817818 # TODO add PAD keys hack as in bpython.cli
818819 elif e in key_dispatch [self .config .edit_current_block_key ]:
819820 self .send_current_block_to_external_editor ()
820- elif e in ( "<ESC>" ,) :
821+ elif e == "<ESC>" :
821822 self .incr_search_mode = SearchMode .NO_SEARCH
822- elif e in ( "<SPACE>" ,) :
823+ elif e == "<SPACE>" :
823824 self .add_normal_character (" " )
824825 elif e in CHARACTER_PAIR_MAP .keys ():
825826 if e in ["'" , '"' ]:
@@ -1093,7 +1094,7 @@ def process_simple_keypress(self, e: str):
10931094 self .process_event (bpythonevents .RefreshRequestEvent ())
10941095 elif isinstance (e , events .Event ):
10951096 pass # ignore events
1096- elif e in ( "<SPACE>" ,) :
1097+ elif e == "<SPACE>" :
10971098 self .add_normal_character (" " )
10981099 else :
10991100 self .add_normal_character (e )
0 commit comments