Show More
@@ -698,6 +698,8 b' class ConsoleWidget(Configurable, QtGui.QWidget):' | |||||
698 | alt_down = event.modifiers() & QtCore.Qt.AltModifier |
|
698 | alt_down = event.modifiers() & QtCore.Qt.AltModifier | |
699 | shift_down = event.modifiers() & QtCore.Qt.ShiftModifier |
|
699 | shift_down = event.modifiers() & QtCore.Qt.ShiftModifier | |
700 |
|
700 | |||
|
701 | #------ Special sequences ---------------------------------------------- | |||
|
702 | ||||
701 | if event.matches(QtGui.QKeySequence.Copy): |
|
703 | if event.matches(QtGui.QKeySequence.Copy): | |
702 | self.copy() |
|
704 | self.copy() | |
703 | intercepted = True |
|
705 | intercepted = True | |
@@ -706,6 +708,45 b' class ConsoleWidget(Configurable, QtGui.QWidget):' | |||||
706 | self.paste() |
|
708 | self.paste() | |
707 | intercepted = True |
|
709 | intercepted = True | |
708 |
|
710 | |||
|
711 | #------ Special modifier logic ----------------------------------------- | |||
|
712 | ||||
|
713 | elif key in (QtCore.Qt.Key_Return, QtCore.Qt.Key_Enter): | |||
|
714 | intercepted = True | |||
|
715 | ||||
|
716 | # Special handling when tab completing in text mode. | |||
|
717 | self._cancel_text_completion() | |||
|
718 | ||||
|
719 | if self._in_buffer(position): | |||
|
720 | if self._reading: | |||
|
721 | self._append_plain_text('\n') | |||
|
722 | self._reading = False | |||
|
723 | if self._reading_callback: | |||
|
724 | self._reading_callback() | |||
|
725 | ||||
|
726 | # If there is only whitespace after the cursor, execute. | |||
|
727 | # Otherwise, split the line with a continuation prompt. | |||
|
728 | elif not self._executing: | |||
|
729 | cursor.movePosition(QtGui.QTextCursor.End, | |||
|
730 | QtGui.QTextCursor.KeepAnchor) | |||
|
731 | at_end = cursor.selectedText().trimmed().isEmpty() | |||
|
732 | if (at_end or shift_down) and not ctrl_down: | |||
|
733 | self.execute(interactive = not shift_down) | |||
|
734 | else: | |||
|
735 | # Do this inside an edit block for clean undo/redo. | |||
|
736 | cursor.beginEditBlock() | |||
|
737 | cursor.setPosition(position) | |||
|
738 | cursor.insertText('\n') | |||
|
739 | self._insert_continuation_prompt(cursor) | |||
|
740 | cursor.endEditBlock() | |||
|
741 | ||||
|
742 | # Ensure that the whole input buffer is visible. | |||
|
743 | # FIXME: This will not be usable if the input buffer is | |||
|
744 | # taller than the console widget. | |||
|
745 | self._control.moveCursor(QtGui.QTextCursor.End) | |||
|
746 | self._control.setTextCursor(cursor) | |||
|
747 | ||||
|
748 | #------ Control/Cmd modifier ------------------------------------------- | |||
|
749 | ||||
709 | elif ctrl_down: |
|
750 | elif ctrl_down: | |
710 | if key == QtCore.Qt.Key_G: |
|
751 | if key == QtCore.Qt.Key_G: | |
711 | self._keyboard_quit() |
|
752 | self._keyboard_quit() | |
@@ -753,6 +794,8 b' class ConsoleWidget(Configurable, QtGui.QWidget):' | |||||
753 | elif key in (QtCore.Qt.Key_Backspace, QtCore.Qt.Key_Delete): |
|
794 | elif key in (QtCore.Qt.Key_Backspace, QtCore.Qt.Key_Delete): | |
754 | intercepted = True |
|
795 | intercepted = True | |
755 |
|
796 | |||
|
797 | #------ Alt modifier --------------------------------------------------- | |||
|
798 | ||||
756 | elif alt_down: |
|
799 | elif alt_down: | |
757 | if key == QtCore.Qt.Key_B: |
|
800 | if key == QtCore.Qt.Key_B: | |
758 | self._set_cursor(self._get_word_start_cursor(position)) |
|
801 | self._set_cursor(self._get_word_start_cursor(position)) | |
@@ -785,43 +828,10 b' class ConsoleWidget(Configurable, QtGui.QWidget):' | |||||
785 | self._control.setTextCursor(self._get_prompt_cursor()) |
|
828 | self._control.setTextCursor(self._get_prompt_cursor()) | |
786 | intercepted = True |
|
829 | intercepted = True | |
787 |
|
830 | |||
788 | else: |
|
831 | #------ No modifiers --------------------------------------------------- | |
789 | if key in (QtCore.Qt.Key_Return, QtCore.Qt.Key_Enter): |
|
|||
790 | intercepted = True |
|
|||
791 |
|
||||
792 | # Special handling when tab completing in text mode. |
|
|||
793 | self._cancel_text_completion() |
|
|||
794 |
|
832 | |||
795 | if self._in_buffer(position): |
|
833 | else: | |
796 | if self._reading: |
|
834 | if key == QtCore.Qt.Key_Escape: | |
797 | self._append_plain_text('\n') |
|
|||
798 | self._reading = False |
|
|||
799 | if self._reading_callback: |
|
|||
800 | self._reading_callback() |
|
|||
801 |
|
||||
802 | # If there is only whitespace after the cursor, execute. |
|
|||
803 | # Otherwise, split the line with a continuation prompt. |
|
|||
804 | elif not self._executing: |
|
|||
805 | cursor.movePosition(QtGui.QTextCursor.End, |
|
|||
806 | QtGui.QTextCursor.KeepAnchor) |
|
|||
807 | at_end = cursor.selectedText().trimmed().isEmpty() |
|
|||
808 | if at_end or shift_down: |
|
|||
809 | self.execute(interactive = not shift_down) |
|
|||
810 | else: |
|
|||
811 | # Do this inside an edit block for clean undo/redo. |
|
|||
812 | cursor.beginEditBlock() |
|
|||
813 | cursor.setPosition(position) |
|
|||
814 | cursor.insertText('\n') |
|
|||
815 | self._insert_continuation_prompt(cursor) |
|
|||
816 | cursor.endEditBlock() |
|
|||
817 |
|
||||
818 | # Ensure that the whole input buffer is visible. |
|
|||
819 | # FIXME: This will not be usable if the input buffer |
|
|||
820 | # is taller than the console widget. |
|
|||
821 | self._control.moveCursor(QtGui.QTextCursor.End) |
|
|||
822 | self._control.setTextCursor(cursor) |
|
|||
823 |
|
||||
824 | elif key == QtCore.Qt.Key_Escape: |
|
|||
825 | self._keyboard_quit() |
|
835 | self._keyboard_quit() | |
826 | intercepted = True |
|
836 | intercepted = True | |
827 |
|
837 |
@@ -152,7 +152,11 b' class HistoryConsoleWidget(ConsoleWidget):' | |||||
152 | history = prefix |
|
152 | history = prefix | |
153 | self.input_buffer = history |
|
153 | self.input_buffer = history | |
154 |
|
154 | |||
155 | def set_history(self, history): |
|
155 | #--------------------------------------------------------------------------- | |
|
156 | # 'HistoryConsoleWidget' protected interface | |||
|
157 | #--------------------------------------------------------------------------- | |||
|
158 | ||||
|
159 | def _set_history(self, history): | |||
156 | """ Replace the current history with a sequence of history items. |
|
160 | """ Replace the current history with a sequence of history items. | |
157 | """ |
|
161 | """ | |
158 | self._history = list(history) |
|
162 | self._history = list(history) |
General Comments 0
You need to be logged in to leave comments.
Login now