@@ -179,10 +179,10 @@ def request_refresh():
179179 self .stderr = FakeOutput (self .coderunner , self .send_to_stderr )
180180 self .stdin = FakeStdin (self .coderunner , self )
181181
182- self .paste_mode = False
183182 self .request_paint_to_clear_screen = False
184183 self .last_events = [None ] * 50
185184 self .presentation_mode = False
185+ self .paste_events = None
186186
187187 self .width = None # will both be set by a window resize event
188188 self .height = None
@@ -219,6 +219,22 @@ def clean_up_current_line_for_exit(self):
219219 self .cursor_offset_in_line = - 1
220220 self .unhighlight_paren ()
221221
222+ def process_paste_events (self ):
223+ for ee in self .paste_events :
224+ if isinstance (ee , events .Event ):
225+ pass
226+ else :
227+ if ee in ("\n " , "\r " , "PAD_ENTER" ):
228+ self .on_enter ()
229+ break
230+ elif isinstance (ee , events .Event ):
231+ pass # ignore events in a paste
232+ else :
233+ self .add_normal_character (ee if len (ee ) == 1 else ee [- 1 ]) #strip control seq
234+ else :
235+ self .self .paste_events = None
236+ self .update_completion ()
237+
222238 ## Event handling
223239 def process_event (self , e ):
224240 """Returns True if shutting down, otherwise mutates state of Repl object"""
@@ -232,7 +248,9 @@ def process_event(self, e):
232248 result = None
233249 logging .debug ("processing event %r" , e )
234250 if isinstance (e , events .RefreshRequestEvent ):
235- if self .status_bar .has_focus :
251+ if self .paste_events :
252+ self .process_paste_events ()
253+ elif self .status_bar .has_focus :
236254 self .status_bar .process_event (e )
237255 else :
238256 assert self .coderunner .code_is_waiting
@@ -250,6 +268,9 @@ def process_event(self, e):
250268 self .keyboard_interrupt ()
251269 self .update_completion ()
252270 return
271+ elif isinstance (e , events .PasteEvent ):
272+ self .paste_events = (event for event in e .events )
273+ self .process_paste_events ()
253274
254275 elif e in self .rl_char_sequences :
255276 self .cursor_offset_in_line , self ._current_line = self .rl_char_sequences [e ](self .cursor_offset_in_line , self ._current_line )
@@ -421,8 +442,6 @@ def update_completion(self, tab=False):
421442 """Update autocomplete info; self.matches and self.argspec"""
422443 #TODO do we really have to do something this ugly? Can we rename it?
423444 # this method stolen from bpython.cli
424- if self .paste_mode :
425- return
426445
427446 if self .list_win_visible and not self .config .auto_display_list :
428447 self .list_win_visible = False
0 commit comments