##// END OF EJS Templates
The FrontendWidget now performs tab-completion more aggressively.
epatters -
Show More
@@ -641,8 +641,10 b' class ConsoleWidget(QtGui.QWidget):'
641 elif key == QtCore.Qt.Key_Tab:
641 elif key == QtCore.Qt.Key_Tab:
642 if self._reading:
642 if self._reading:
643 intercepted = False
643 intercepted = False
644 elif not self._tab_pressed():
645 intercepted = True
644 else:
646 else:
645 intercepted = not self._tab_pressed()
647 intercepted = not self._in_buffer()
646
648
647 elif key == QtCore.Qt.Key_Left:
649 elif key == QtCore.Qt.Key_Left:
648 intercepted = not self._in_buffer(position - 1)
650 intercepted = not self._in_buffer(position - 1)
@@ -968,11 +970,15 b' class ConsoleWidget(QtGui.QWidget):'
968 cursor.endEditBlock()
970 cursor.endEditBlock()
969 self._control.setTextCursor(cursor)
971 self._control.setTextCursor(cursor)
970
972
971 def _in_buffer(self, position):
973 def _in_buffer(self, position=None):
972 """ Returns whether the given position is inside the editing region.
974 """ Returns whether the current cursor (or, if specified, a position) is
975 inside the editing region.
973 """
976 """
974 cursor = self._control.textCursor()
977 cursor = self._control.textCursor()
975 cursor.setPosition(position)
978 if position is None:
979 position = cursor.position()
980 else:
981 cursor.setPosition(position)
976 line = cursor.blockNumber()
982 line = cursor.blockNumber()
977 prompt_line = self._get_prompt_cursor().blockNumber()
983 prompt_line = self._get_prompt_cursor().blockNumber()
978 if line == prompt_line:
984 if line == prompt_line:
@@ -987,13 +993,12 b' class ConsoleWidget(QtGui.QWidget):'
987 """ Ensures that the cursor is inside the editing region. Returns
993 """ Ensures that the cursor is inside the editing region. Returns
988 whether the cursor was moved.
994 whether the cursor was moved.
989 """
995 """
990 cursor = self._control.textCursor()
996 moved = not self._in_buffer()
991 if self._in_buffer(cursor.position()):
997 if moved:
992 return False
998 cursor = self._control.textCursor()
993 else:
994 cursor.movePosition(QtGui.QTextCursor.End)
999 cursor.movePosition(QtGui.QTextCursor.End)
995 self._control.setTextCursor(cursor)
1000 self._control.setTextCursor(cursor)
996 return True
1001 return moved
997
1002
998 def _page(self, text):
1003 def _page(self, text):
999 """ Displays text using the pager if it exceeds the height of the
1004 """ Displays text using the pager if it exceeds the height of the
@@ -148,9 +148,16 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
148 """ Called when the tab key is pressed. Returns whether to continue
148 """ Called when the tab key is pressed. Returns whether to continue
149 processing the event.
149 processing the event.
150 """
150 """
151 self._keep_cursor_in_buffer()
151 # Perform tab completion if:
152 cursor = self._get_cursor()
152 # 1) The cursor is in the input buffer.
153 return not self._complete()
153 # 2) There is a non-whitespace character before the cursor.
154 text = self._get_input_buffer_cursor_line()
155 if text is None:
156 return False
157 complete = bool(text[:self._get_input_buffer_cursor_column()].strip())
158 if complete:
159 self._complete()
160 return not complete
154
161
155 #---------------------------------------------------------------------------
162 #---------------------------------------------------------------------------
156 # 'ConsoleWidget' protected interface
163 # 'ConsoleWidget' protected interface
General Comments 0
You need to be logged in to leave comments. Login now