##// END OF EJS Templates
* Fixed bug where syntax highlighting was lost after updating a prompt with a bad number....
epatters -
Show More
@@ -893,12 +893,17 b' class ConsoleWidget(QtGui.QWidget):'
893 """ Inserts HTML using the specified cursor, then returns its plain text
893 """ Inserts HTML using the specified cursor, then returns its plain text
894 version.
894 version.
895 """
895 """
896 cursor.beginEditBlock()
897 cursor.removeSelectedText()
898
896 start = cursor.position()
899 start = cursor.position()
897 self._insert_html(cursor, html)
900 self._insert_html(cursor, html)
898 end = cursor.position()
901 end = cursor.position()
899 cursor.setPosition(start, QtGui.QTextCursor.KeepAnchor)
902 cursor.setPosition(start, QtGui.QTextCursor.KeepAnchor)
900 text = str(cursor.selection().toPlainText())
903 text = str(cursor.selection().toPlainText())
904
901 cursor.setPosition(end)
905 cursor.setPosition(end)
906 cursor.endEditBlock()
902 return text
907 return text
903
908
904 def _insert_plain_text(self, cursor, text):
909 def _insert_plain_text(self, cursor, text):
@@ -69,6 +69,10 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
69 # processed by the FrontendWidget.
69 # processed by the FrontendWidget.
70 executed = QtCore.pyqtSignal(object)
70 executed = QtCore.pyqtSignal(object)
71
71
72 # Protected class attributes.
73 _highlighter_class = FrontendHighlighter
74 _input_splitter_class = InputSplitter
75
72 #---------------------------------------------------------------------------
76 #---------------------------------------------------------------------------
73 # 'object' interface
77 # 'object' interface
74 #---------------------------------------------------------------------------
78 #---------------------------------------------------------------------------
@@ -80,8 +84,8 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
80 self._call_tip_widget = CallTipWidget(self._control)
84 self._call_tip_widget = CallTipWidget(self._control)
81 self._completion_lexer = CompletionLexer(PythonLexer())
85 self._completion_lexer = CompletionLexer(PythonLexer())
82 self._hidden = True
86 self._hidden = True
83 self._highlighter = FrontendHighlighter(self)
87 self._highlighter = self._highlighter_class(self)
84 self._input_splitter = InputSplitter(input_mode='replace')
88 self._input_splitter = self._input_splitter_class(input_mode='replace')
85 self._kernel_manager = None
89 self._kernel_manager = None
86
90
87 # Configure the ConsoleWidget.
91 # Configure the ConsoleWidget.
@@ -51,6 +51,9 b' class IPythonWidget(FrontendWidget):'
51 in_prompt = '<br/>In [<span class="in-prompt-number">%i</span>]: '
51 in_prompt = '<br/>In [<span class="in-prompt-number">%i</span>]: '
52 out_prompt = 'Out[<span class="out-prompt-number">%i</span>]: '
52 out_prompt = 'Out[<span class="out-prompt-number">%i</span>]: '
53
53
54 # FrontendWidget protected class attributes.
55 #_input_splitter_class = IPythonInputSplitter
56
54 #---------------------------------------------------------------------------
57 #---------------------------------------------------------------------------
55 # 'object' interface
58 # 'object' interface
56 #---------------------------------------------------------------------------
59 #---------------------------------------------------------------------------
@@ -58,9 +61,6 b' class IPythonWidget(FrontendWidget):'
58 def __init__(self, *args, **kw):
61 def __init__(self, *args, **kw):
59 super(IPythonWidget, self).__init__(*args, **kw)
62 super(IPythonWidget, self).__init__(*args, **kw)
60
63
61 # FrontendWidget protected variables.
62 #self._input_splitter = IPythonInputSplitter(input_mode='replace')
63
64 # IPythonWidget protected variables.
64 # IPythonWidget protected variables.
65 self._previous_prompt_obj = None
65 self._previous_prompt_obj = None
66
66
@@ -141,12 +141,23 b' class IPythonWidget(FrontendWidget):'
141 self._previous_prompt_obj.number != previous_prompt_number:
141 self._previous_prompt_obj.number != previous_prompt_number:
142 block = self._previous_prompt_obj.block
142 block = self._previous_prompt_obj.block
143 if block.isValid():
143 if block.isValid():
144
145 # Remove the old prompt and insert a new prompt.
144 cursor = QtGui.QTextCursor(block)
146 cursor = QtGui.QTextCursor(block)
145 cursor.movePosition(QtGui.QTextCursor.Right,
147 cursor.movePosition(QtGui.QTextCursor.Right,
146 QtGui.QTextCursor.KeepAnchor,
148 QtGui.QTextCursor.KeepAnchor,
147 self._previous_prompt_obj.length)
149 self._previous_prompt_obj.length)
148 prompt = self._make_in_prompt(previous_prompt_number)
150 prompt = self._make_in_prompt(previous_prompt_number)
149 self._insert_html(cursor, prompt)
151 self._prompt = self._insert_html_fetching_plain_text(
152 cursor, prompt)
153
154 # XXX: When the HTML is inserted, Qt blows away the syntax
155 # highlighting for the line. I cannot for the life of me
156 # determine how to preserve the existing formatting.
157 self._highlighter.highlighting_on = True
158 self._highlighter.rehighlightBlock(cursor.block())
159 self._highlighter.highlighting_on = False
160
150 self._previous_prompt_obj = None
161 self._previous_prompt_obj = None
151
162
152 # Show a new prompt with the kernel's estimated prompt number.
163 # Show a new prompt with the kernel's estimated prompt number.
General Comments 0
You need to be logged in to leave comments. Login now