##// END OF EJS Templates
ENH: Better handling of continuation lines
Gael Varoquaux -
Show More
@@ -401,17 +401,28 b' class ConsoleWidget(editwindow.EditWindow):'
401 401 catched = True
402 402
403 403 elif event.KeyCode in (wx.WXK_LEFT, wx.WXK_BACK):
404 if not self._keep_cursor_in_buffer():
404 if not self._keep_cursor_in_buffer(self.GetCurrentPos() - 1):
405 event.Skip()
406 catched = True
407
408 elif event.KeyCode == wx.WXK_RIGHT:
409 if not self._keep_cursor_in_buffer(self.GetCurrentPos() + 1):
410 event.Skip()
411 catched = True
412
413
414 elif event.KeyCode == wx.WXK_DELETE:
415 if not self._keep_cursor_in_buffer(self.GetCurrentPos() - 1):
405 416 event.Skip()
406 417 catched = True
407 418
408 419 if skip and not catched:
409 420 # Put the cursor back in the edit region
410 421 if not self._keep_cursor_in_buffer():
411 if (self.GetCurrentPos() == self.GetLength()
422 if not (self.GetCurrentPos() == self.GetLength()
412 423 and event.KeyCode == wx.WXK_DELETE):
413 pass
414 event.Skip()
424 event.Skip()
425 catched = True
415 426
416 427 return catched
417 428
@@ -424,7 +435,7 b' class ConsoleWidget(editwindow.EditWindow):'
424 435 self._keep_cursor_in_buffer()
425 436
426 437
427 def _keep_cursor_in_buffer(self):
438 def _keep_cursor_in_buffer(self, pos=None):
428 439 """ Checks if the cursor is where it is allowed to be. If not,
429 440 put it back.
430 441
@@ -438,11 +449,19 b' class ConsoleWidget(editwindow.EditWindow):'
438 449 WARNING: This does proper checks only for horizontal
439 450 movements.
440 451 """
441 current_pos = self.GetCurrentPos()
452 if pos is None:
453 current_pos = self.GetCurrentPos()
454 else:
455 current_pos = pos
442 456 if current_pos < self.current_prompt_pos:
443 457 self.GotoPos(self.current_prompt_pos)
444 458 return True
445 line, line_pos = self.GetCurLine()
459 line_num = self.LineFromPosition(current_pos)
460 if not current_pos > self.GetLength():
461 line_pos = self.GetColumn(current_pos)
462 else:
463 line_pos = self.GetColumn(self.GetLength())
464 line = self.GetLine(line_num)
446 465 # Jump the continuation prompt
447 466 continuation_prompt = self.continuation_prompt()
448 467 if ( line.startswith(continuation_prompt)
@@ -454,7 +473,13 b' class ConsoleWidget(editwindow.EditWindow):'
454 473 len(continuation_prompt) - line_pos)
455 474 else:
456 475 # Jump back up
457 self.GotoPos(self.GetLineEndPosition(self.GetCurrentLine()-1))
476 self.GotoPos(self.GetLineEndPosition(line_num-1))
477 return True
478 elif ( current_pos > self.GetLineEndPosition(line_num)
479 and not current_pos == self.GetLength()):
480 # Jump to next line
481 self.GotoPos(current_pos + 1 +
482 len(continuation_prompt))
458 483 return True
459 484 return False
460 485
General Comments 0
You need to be logged in to leave comments. Login now