##// END OF EJS Templates
refactor to improve cell switching in edit mode...
refactor to improve cell switching in edit mode This code was repeated in both CodeCell and TextCell, both of which are extensions of Cell, so this just unifies the logic in Cell. TextCell had logic here to check if the cell was rendered or not, but I don't believe it is possible to end up triggering such a code path. (Should that be required, I can always just add back these methods to TextCell, performing the .rendered==True check, and calling the Cell prior to this, code mirror at_top would only return true on if the cursor was at the first character of the top line. Now, pressing up arrow on any character on the top line will take you to the cell above. The same applies for the bottom line. Pressing down arrow would only go to the next cell if the cursor was at a location *after* the last character (something that is only possible to achieve in vim mode if the last line is empty, for example). Now, down arrow on any character of the last line will go to the next cell.

File last commit:

r13888:74d7ea88
r15754:d60e793e
Show More
completion_plain.py
62 lines | 2.3 KiB | text/x-python | PythonLexer
/ IPython / qt / console / completion_plain.py
Thomas Kluyver
Standardise some module docstring first lines
r13888 """A simple completer for the qtconsole"""
Matthias BUSSONNIER
new completer for qtconsole...
r7393 #-----------------------------------------------------------------------------
# Copyright (c) 2012, IPython Development Team.$
#
# Distributed under the terms of the Modified BSD License.$
#
# The full license is in the file COPYING.txt, distributed with this software.
#-------------------------------------------------------------------
Matthias BUSSONNIER
new completer for qtconsole....
r7389 # System library imports
from IPython.external.qt import QtCore, QtGui
Matthias BUSSONNIER
new completer for qtconsole...
r7393 import IPython.utils.text as text
Matthias BUSSONNIER
new completer for qtconsole....
r7389
class CompletionPlain(QtGui.QWidget):
""" A widget for tab completion, navigable by arrow keys """
#--------------------------------------------------------------------------
# 'QObject' interface
#--------------------------------------------------------------------------
def __init__(self, console_widget):
""" Create a completion widget that is attached to the specified Qt
text edit widget.
"""
assert isinstance(console_widget._control, (QtGui.QTextEdit, QtGui.QPlainTextEdit))
super(CompletionPlain, self).__init__()
self._text_edit = console_widget._control
self._console_widget = console_widget
self._text_edit.installEventFilter(self)
def eventFilter(self, obj, event):
""" Reimplemented to handle keyboard input and to auto-hide when the
text edit loses focus.
"""
if obj == self._text_edit:
etype = event.type()
Matthias BUSSONNIER
new completer for qtconsole...
r7393 if etype in( QtCore.QEvent.KeyPress, QtCore.QEvent.FocusOut ):
self.cancel_completion()
Matthias BUSSONNIER
new completer for qtconsole....
r7389
return super(CompletionPlain, self).eventFilter(obj, event)
#--------------------------------------------------------------------------
# 'CompletionPlain' interface
#--------------------------------------------------------------------------
Matthias BUSSONNIER
new completer for qtconsole...
r7393 def cancel_completion(self):
Matthias BUSSONNIER
new completer for qtconsole....
r7389 """Cancel the completion, reseting internal variable, clearing buffer """
self._console_widget._clear_temporary_buffer()
def show_items(self, cursor, items):
""" Shows the completion widget with 'items' at the position specified
by 'cursor'.
"""
if not items :
return
Matthias BUSSONNIER
new completer for qtconsole...
r7393 self.cancel_completion()
strng = text.columnize(items)
self._console_widget._fill_temporary_buffer(cursor, strng, html=False)