##// END OF EJS Templates
ENH: Backspace now deletes continuation lines
Gael Varoquaux -
Show More
@@ -242,7 +242,9 b' class ConsoleWidget(editwindow.EditWindow):'
242
242
243
243
244 def continuation_prompt(self):
244 def continuation_prompt(self):
245 """Returns the current continuation prompt.
245 """ Returns the current continuation prompt.
246 We need to implement this method here to deal with the
247 ascii escape sequences cleaning up.
246 """
248 """
247 # ASCII-less prompt
249 # ASCII-less prompt
248 ascii_less = ''.join(self.color_pat.split(self.last_prompt)[2::2])
250 ascii_less = ''.join(self.color_pat.split(self.last_prompt)[2::2])
@@ -271,21 +273,6 b' class ConsoleWidget(editwindow.EditWindow):'
271 return self.GetSize()[0]/self.GetCharWidth()
273 return self.GetSize()[0]/self.GetCharWidth()
272
274
273
275
274
275 #--------------------------------------------------------------------------
276 # EditWindow API
277 #--------------------------------------------------------------------------
278
279 def OnUpdateUI(self, event):
280 """ Override the OnUpdateUI of the EditWindow class, to prevent
281 syntax highlighting both for faster redraw, and for more
282 consistent look and feel.
283 """
284
285 #--------------------------------------------------------------------------
286 # Styling API
287 #--------------------------------------------------------------------------
288
289 def configure_scintilla(self):
276 def configure_scintilla(self):
290
277
291 p = self.style
278 p = self.style
@@ -461,7 +448,18 b' class ConsoleWidget(editwindow.EditWindow):'
461 self.SetEdgeMode(stc.STC_EDGE_LINE)
448 self.SetEdgeMode(stc.STC_EDGE_LINE)
462 self.SetEdgeColumn(88)
449 self.SetEdgeColumn(88)
463
450
464
451
452 #--------------------------------------------------------------------------
453 # EditWindow API
454 #--------------------------------------------------------------------------
455
456 def OnUpdateUI(self, event):
457 """ Override the OnUpdateUI of the EditWindow class, to prevent
458 syntax highlighting both for faster redraw, and for more
459 consistent look and feel.
460 """
461
462
465 #--------------------------------------------------------------------------
463 #--------------------------------------------------------------------------
466 # Private API
464 # Private API
467 #--------------------------------------------------------------------------
465 #--------------------------------------------------------------------------
@@ -572,6 +570,7 b' class ConsoleWidget(editwindow.EditWindow):'
572 self._keep_cursor_in_buffer()
570 self._keep_cursor_in_buffer()
573
571
574
572
573 # XXX: I need to avoid the problem of having an empty glass;
575 def _keep_cursor_in_buffer(self, pos=None):
574 def _keep_cursor_in_buffer(self, pos=None):
576 """ Checks if the cursor is where it is allowed to be. If not,
575 """ Checks if the cursor is where it is allowed to be. If not,
577 put it back.
576 put it back.
@@ -602,7 +601,7 b' class ConsoleWidget(editwindow.EditWindow):'
602 # Jump the continuation prompt
601 # Jump the continuation prompt
603 continuation_prompt = self.continuation_prompt()
602 continuation_prompt = self.continuation_prompt()
604 if ( line.startswith(continuation_prompt)
603 if ( line.startswith(continuation_prompt)
605 and line_pos < len(continuation_prompt)+1):
604 and line_pos < len(continuation_prompt)):
606 if line_pos < 2:
605 if line_pos < 2:
607 # We are at the beginning of the line, trying to move
606 # We are at the beginning of the line, trying to move
608 # forward: jump forward.
607 # forward: jump forward.
@@ -459,8 +459,36 b' class WxController(ConsoleWidget, PrefilterFrontEnd):'
459 wx.CallAfter(self._popup_completion, create=True)
459 wx.CallAfter(self._popup_completion, create=True)
460 else:
460 else:
461 event.Skip()
461 event.Skip()
462 elif event.KeyCode == wx.WXK_BACK:
463 # If characters where erased, check if we have to
464 # remove a line.
465 # XXX: What about DEL?
466 current_line, _ = self.CurLine
467 current_pos = self.GetCurrentPos()
468 current_line_number = self.LineFromPosition(current_pos)
469 current_col = self.GetColumn(current_pos)
470 len_prompt = len(self.continuation_prompt())
471 if ( current_line.startswith(self.continuation_prompt())
472 and current_col == len_prompt):
473 print 'BACK', current_line, self.current_prompt_line, \
474 current_line_number
475 new_lines = []
476 for line_num, line in enumerate(
477 self.input_buffer.split('\n')):
478 if (line_num + self.current_prompt_line ==
479 current_line_number):
480 new_lines.append(line[len_prompt:])
481 else:
482 new_lines.append('\n'+line)
483 # The first character is '\n', due to the above
484 # code:
485 self.input_buffer = ''.join(new_lines)[1:]
486 self.GotoPos(current_pos - 1 - len_prompt)
487 else:
488 ConsoleWidget._on_key_down(self, event, skip=skip)
462 else:
489 else:
463 ConsoleWidget._on_key_down(self, event, skip=skip)
490 ConsoleWidget._on_key_down(self, event, skip=skip)
491
464
492
465
493
466 def _on_key_up(self, event, skip=True):
494 def _on_key_up(self, event, skip=True):
@@ -472,11 +500,15 b' class WxController(ConsoleWidget, PrefilterFrontEnd):'
472 wx.CallAfter(self._popup_completion, create=True)
500 wx.CallAfter(self._popup_completion, create=True)
473 else:
501 else:
474 ConsoleWidget._on_key_up(self, event, skip=skip)
502 ConsoleWidget._on_key_up(self, event, skip=skip)
475 if (self.input_buffer.split('\n')[-1] == self.continuation_prompt()
503 # Make sure the continuation_prompts are always followed by a
476 and self._input_state == 'readline'):
504 # whitespace
477 # Make sure the continuation_prompt is followed by a whitespace
505 new_lines = []
506 if self._input_state == 'readline':
478 position = self.GetCurrentPos()
507 position = self.GetCurrentPos()
479 self.input_buffer += ' '
508 for line in self.input_buffer.split('\n'):
509 if not line == self.continuation_prompt()[:-1]:
510 new_lines.append(line)
511 self.input_buffer = '\n'.join(new_lines)
480 self.GotoPos(position)
512 self.GotoPos(position)
481
513
482
514
General Comments 0
You need to be logged in to leave comments. Login now