@@ -122,58 +122,59 @@ def process_event(self, e: Union[events.Event, str]) -> None:
122
122
assert self .has_focus
123
123
124
124
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
144
132
self .has_focus = False
145
133
self .current_line = ""
146
134
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>" ,):
149
142
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 )
159
161
160
162
if self .current_line .endswith (("\n " , "\r " )):
161
163
pass
162
164
else :
163
165
self .repl .send_to_stdin (self .current_line )
164
166
165
167
def add_input_character (self , e : str ) -> None :
166
- if e in ( "<SPACE>" ,) :
168
+ if e == "<SPACE>" :
167
169
e = " "
168
170
if e .startswith ("<" ) and e .endswith (">" ):
169
171
return
170
172
assert len (e ) == 1 , "added multiple characters: %r" % e
171
173
logger .debug ("adding normal char %r to current line" , e )
172
174
173
- c = e
174
175
self .current_line = (
175
176
self .current_line [: self .cursor_offset ]
176
- + c
177
+ + e
177
178
+ self .current_line [self .cursor_offset :]
178
179
)
179
180
self .cursor_offset += 1
@@ -756,11 +757,11 @@ def process_key_event(self, e: str) -> None:
756
757
self .up_one_line ()
757
758
elif e in ("<DOWN>" ,) + key_dispatch [self .config .down_one_line_key ]:
758
759
self .down_one_line ()
759
- elif e in ( "<Ctrl-d>" ,) :
760
+ elif e == "<Ctrl-d>" :
760
761
self .on_control_d ()
761
- elif e in ( "<Ctrl-o>" ,) :
762
+ elif e == "<Ctrl-o>" :
762
763
self .operate_and_get_next ()
763
- elif e in ( "<Esc+.>" ,) :
764
+ elif e == "<Esc+.>" :
764
765
self .get_last_word ()
765
766
elif e in key_dispatch [self .config .reverse_incremental_search_key ]:
766
767
self .incremental_search (reverse = True )
@@ -796,9 +797,9 @@ def process_key_event(self, e: str) -> None:
796
797
raise SystemExit ()
797
798
elif e in ("\n " , "\r " , "<PADENTER>" , "<Ctrl-j>" , "<Ctrl-m>" ):
798
799
self .on_enter ()
799
- elif e in ( "<TAB>" ,) : # tab
800
+ elif e == "<TAB>" : # tab
800
801
self .on_tab ()
801
- elif e in ( "<Shift-TAB>" ,) :
802
+ elif e == "<Shift-TAB>" :
802
803
self .on_tab (back = True )
803
804
elif e in key_dispatch [self .config .undo_key ]: # ctrl-r for undo
804
805
self .prompt_undo ()
@@ -817,9 +818,9 @@ def process_key_event(self, e: str) -> None:
817
818
# TODO add PAD keys hack as in bpython.cli
818
819
elif e in key_dispatch [self .config .edit_current_block_key ]:
819
820
self .send_current_block_to_external_editor ()
820
- elif e in ( "<ESC>" ,) :
821
+ elif e == "<ESC>" :
821
822
self .incr_search_mode = SearchMode .NO_SEARCH
822
- elif e in ( "<SPACE>" ,) :
823
+ elif e == "<SPACE>" :
823
824
self .add_normal_character (" " )
824
825
elif e in CHARACTER_PAIR_MAP .keys ():
825
826
if e in ["'" , '"' ]:
@@ -1093,7 +1094,7 @@ def process_simple_keypress(self, e: str):
1093
1094
self .process_event (bpythonevents .RefreshRequestEvent ())
1094
1095
elif isinstance (e , events .Event ):
1095
1096
pass # ignore events
1096
- elif e in ( "<SPACE>" ,) :
1097
+ elif e == "<SPACE>" :
1097
1098
self .add_normal_character (" " )
1098
1099
else :
1099
1100
self .add_normal_character (e )
0 commit comments