@@ -170,11 +170,12 @@ class BPythonEdit(urwid.Edit):
170170
171171 signals = ['edit-pos-changed' ]
172172
173- def __init__ (self , * args , ** kwargs ):
173+ def __init__ (self , tab_length , * args , ** kwargs ):
174174 self ._bpy_text = ''
175175 self ._bpy_attr = []
176176 self ._bpy_selectable = True
177177 self ._bpy_may_move_cursor = False
178+ self .tab_length = tab_length
178179 urwid .Edit .__init__ (self , * args , ** kwargs )
179180
180181 def set_edit_pos (self , pos ):
@@ -242,6 +243,12 @@ def keypress(self, size, key):
242243 # Do not handle up/down arrow, leave them for the repl.
243244 if urwid .command_map [key ] in ('cursor up' , 'cursor down' ):
244245 return key
246+ elif key == 'backspace' :
247+ line = self .get_edit_text ()
248+ cpos = len (line ) - self .edit_pos
249+ if not (cpos or len (line ) % self .tab_length or line .strip ()):
250+ self .set_edit_text (line [:- self .tab_length ])
251+ return None
245252 return urwid .Edit .keypress (self , size , key )
246253 finally :
247254 self ._bpy_may_move_cursor = False
@@ -553,10 +560,12 @@ def prompt(self, more):
553560 self .rl_history .reset ()
554561 # XXX what is s_hist?
555562 if not more :
556- self .edit = BPythonEdit (caption = ('prompt' , '>>> ' ))
563+ self .edit = BPythonEdit (self .config .tab_length ,
564+ caption = ('prompt' , '>>> ' ))
557565 self .stdout_hist += '>>> '
558566 else :
559- self .edit = BPythonEdit (caption = ('prompt_more' , '... ' ))
567+ self .edit = BPythonEdit (self .config .tab_length ,
568+ caption = ('prompt_more' , '... ' ))
560569 self .stdout_hist += '... '
561570
562571 urwid .connect_signal (self .edit , 'change' , self .on_input_change )
0 commit comments