From c0c568a3481cf339fc84c1c1e785dc39d54a90d0 2010-09-02 19:16:04 From: epatters Date: 2010-09-02 19:16:04 Subject: [PATCH] * Fixed bug with terminal-style tab completion for multi-line input. * Improved tab completion for long text with '.' and path separators. --- diff --git a/IPython/frontend/qt/console/console_widget.py b/IPython/frontend/qt/console/console_widget.py index f147164..8295e33 100644 --- a/IPython/frontend/qt/console/console_widget.py +++ b/IPython/frontend/qt/console/console_widget.py @@ -563,11 +563,15 @@ class ConsoleWidget(Configurable, QtGui.QWidget): the prompt region. """ cursor = self._get_prompt_cursor() - found_block = cursor.movePosition(QtGui.QTextCursor.NextBlock) - if found_block: - while found_block and \ - cursor.block().text().startsWith(self._continuation_prompt): - found_block = cursor.movePosition(QtGui.QTextCursor.NextBlock) + if cursor.movePosition(QtGui.QTextCursor.NextBlock): + prompt = self._continuation_prompt.lstrip() + while True: + temp_cursor = QtGui.QTextCursor(cursor) + temp_cursor.select(QtGui.QTextCursor.BlockUnderCursor) + text = str(temp_cursor.selection().toPlainText()).lstrip() + if not text.startswith(prompt) or \ + not cursor.movePosition(QtGui.QTextCursor.NextBlock): + break cursor.movePosition(QtGui.QTextCursor.Left) # Grab the newline. cursor.movePosition(QtGui.QTextCursor.End, QtGui.QTextCursor.KeepAnchor) diff --git a/IPython/frontend/qt/console/ipython_widget.py b/IPython/frontend/qt/console/ipython_widget.py index 7fdd9d6..d2828f5 100644 --- a/IPython/frontend/qt/console/ipython_widget.py +++ b/IPython/frontend/qt/console/ipython_widget.py @@ -12,6 +12,7 @@ # Standard library imports from collections import namedtuple +import re from subprocess import Popen # System library imports @@ -127,12 +128,20 @@ class IPythonWidget(FrontendWidget): cursor = self._get_cursor() if rep['parent_header']['msg_id'] == self._complete_id and \ cursor.position() == self._complete_pos: - # The completer tells us what text was actually used for the - # matching, so we must move that many characters left to apply the - # completions. + matches = rep['content']['matches'] text = rep['content']['matched_text'] + + # Clean up matches with '.'s and path separators. + parts = re.split(r'[./\\]', text) + sep_count = len(parts) - 1 + if sep_count: + chop_length = sum(map(len, parts[:sep_count])) + sep_count + matches = [ match[chop_length:] for match in matches ] + text = text[chop_length:] + + # Move the cursor to the start of the match and complete. cursor.movePosition(QtGui.QTextCursor.Left, n=len(text)) - self._complete_with_items(cursor, rep['content']['matches']) + self._complete_with_items(cursor, matches) def _handle_history_reply(self, msg): """ Implemented to handle history replies, which are only supported by