##// END OF EJS Templates
Removed use of hard tabs in FrontendWidget and implemented "smart" backspace.
epatters -
Show More
@@ -1163,8 +1163,8 class ConsoleWidget(Configurable, QtGui.QWidget):
1163 1163 return cursor.columnNumber() - len(prompt)
1164 1164
1165 1165 def _get_input_buffer_cursor_line(self):
1166 """ Returns line of the input buffer that contains the cursor, or None
1167 if there is no such line.
1166 """ Returns the text of the line of the input buffer that contains the
1167 cursor, or None if there is no such line.
1168 1168 """
1169 1169 prompt = self._get_input_buffer_cursor_prompt()
1170 1170 if prompt is None:
@@ -147,11 +147,9 class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):
147 147 """
148 148 text = str(self._control.textCursor().selection().toPlainText())
149 149 if text:
150 # Remove prompts.
151 150 lines = map(transform_classic_prompt, text.splitlines())
152 151 text = '\n'.join(lines)
153 # Expand tabs so that we respect PEP-8.
154 QtGui.QApplication.clipboard().setText(text.expandtabs(4))
152 QtGui.QApplication.clipboard().setText(text)
155 153
156 154 #---------------------------------------------------------------------------
157 155 # 'ConsoleWidget' abstract interface
@@ -162,7 +160,7 class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):
162 160 prompt created. When triggered by an Enter/Return key press,
163 161 'interactive' is True; otherwise, it is False.
164 162 """
165 complete = self._input_splitter.push(source.expandtabs(4))
163 complete = self._input_splitter.push(source)
166 164 if interactive:
167 165 complete = not self._input_splitter.push_accepts_more()
168 166 return complete
@@ -220,26 +218,43 class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):
220 218 return menu
221 219
222 220 def _event_filter_console_keypress(self, event):
223 """ Reimplemented to allow execution interruption.
221 """ Reimplemented for execution interruption and smart backspace.
224 222 """
225 223 key = event.key()
226 224 if self._control_key_down(event.modifiers(), include_command=False):
225
227 226 if key == QtCore.Qt.Key_C and self._executing:
228 227 self.interrupt_kernel()
229 228 return True
229
230 230 elif key == QtCore.Qt.Key_Period:
231 231 message = 'Are you sure you want to restart the kernel?'
232 232 self.restart_kernel(message, instant_death=False)
233 233 return True
234
235 elif not event.modifiers() & QtCore.Qt.AltModifier:
236
237 # Smart backspace: remove four characters in one backspace if:
238 # 1) everything left of the cursor is whitespace
239 # 2) the four characters immediately left of the cursor are spaces
240 if key == QtCore.Qt.Key_Backspace:
241 col = self._get_input_buffer_cursor_column()
242 cursor = self._control.textCursor()
243 if col > 3 and not cursor.hasSelection():
244 text = self._get_input_buffer_cursor_line()[:col]
245 if text.endswith(' ') and not text.strip():
246 cursor.movePosition(QtGui.QTextCursor.Left,
247 QtGui.QTextCursor.KeepAnchor, 4)
248 cursor.removeSelectedText()
249 return True
250
234 251 return super(FrontendWidget, self)._event_filter_console_keypress(event)
235 252
236 253 def _insert_continuation_prompt(self, cursor):
237 254 """ Reimplemented for auto-indentation.
238 255 """
239 256 super(FrontendWidget, self)._insert_continuation_prompt(cursor)
240 spaces = self._input_splitter.indent_spaces
241 cursor.insertText('\t' * (spaces / self.tab_width))
242 cursor.insertText(' ' * (spaces % self.tab_width))
257 cursor.insertText(' ' * self._input_splitter.indent_spaces)
243 258
244 259 #---------------------------------------------------------------------------
245 260 # 'BaseFrontendMixin' abstract interface
@@ -208,11 +208,9 class IPythonWidget(FrontendWidget):
208 208 """
209 209 text = str(self._control.textCursor().selection().toPlainText())
210 210 if text:
211 # Remove prompts.
212 211 lines = map(transform_ipy_prompt, text.splitlines())
213 212 text = '\n'.join(lines)
214 # Expand tabs so that we respect PEP-8.
215 QtGui.QApplication.clipboard().setText(text.expandtabs(4))
213 QtGui.QApplication.clipboard().setText(text)
216 214
217 215 #---------------------------------------------------------------------------
218 216 # 'FrontendWidget' public interface
General Comments 0
You need to be logged in to leave comments. Login now