##// END OF EJS Templates
Fixed bug reported by fperez and removed code with duplicated functionality.
epatters -
Show More
@@ -236,12 +236,8 b' class ConsoleWidget(Configurable, QtGui.QWidget):'
236 elif etype == QtCore.QEvent.Drop and obj == self._control.viewport():
236 elif etype == QtCore.QEvent.Drop and obj == self._control.viewport():
237 cursor = self._control.cursorForPosition(event.pos())
237 cursor = self._control.cursorForPosition(event.pos())
238 if self._in_buffer(cursor.position()):
238 if self._in_buffer(cursor.position()):
239 # The text cursor is not updated during the drag.
240 self._control.setTextCursor(cursor)
241
242 # Now we can perform the insertion manually.
243 text = unicode(event.mimeData().text())
239 text = unicode(event.mimeData().text())
244 self._insert_plain_text_into_buffer(text)
240 self._insert_plain_text_into_buffer(cursor, text)
245
241
246 # Qt is expecting to get something here--drag and drop occurs in its
242 # Qt is expecting to get something here--drag and drop occurs in its
247 # own event loop. Send a DragLeave event to end it.
243 # own event loop. Send a DragLeave event to end it.
@@ -455,15 +451,7 b' class ConsoleWidget(Configurable, QtGui.QWidget):'
455 cursor.removeSelectedText()
451 cursor.removeSelectedText()
456
452
457 # Insert new text with continuation prompts.
453 # Insert new text with continuation prompts.
458 lines = string.splitlines(True)
454 self._insert_plain_text_into_buffer(self._get_prompt_cursor(), string)
459 if lines:
460 self._append_plain_text(lines[0])
461 for i in xrange(1, len(lines)):
462 if self._continuation_prompt_html is None:
463 self._append_plain_text(self._continuation_prompt)
464 else:
465 self._append_html(self._continuation_prompt_html)
466 self._append_plain_text(lines[i])
467 cursor.endEditBlock()
455 cursor.endEditBlock()
468 self._control.moveCursor(QtGui.QTextCursor.End)
456 self._control.moveCursor(QtGui.QTextCursor.End)
469
457
@@ -501,10 +489,14 b' class ConsoleWidget(Configurable, QtGui.QWidget):'
501 in Mac OS. By default, the regular clipboard is used.
489 in Mac OS. By default, the regular clipboard is used.
502 """
490 """
503 if self._control.textInteractionFlags() & QtCore.Qt.TextEditable:
491 if self._control.textInteractionFlags() & QtCore.Qt.TextEditable:
492 # Make sure the paste is safe.
493 self._keep_cursor_in_buffer()
494 cursor = self._control.textCursor()
495
504 # Remove any trailing newline, which confuses the GUI and forces the
496 # Remove any trailing newline, which confuses the GUI and forces the
505 # user to backspace.
497 # user to backspace.
506 text = unicode(QtGui.QApplication.clipboard().text(mode)).rstrip()
498 text = unicode(QtGui.QApplication.clipboard().text(mode)).rstrip()
507 self._insert_plain_text_into_buffer(dedent(text))
499 self._insert_plain_text_into_buffer(cursor, dedent(text))
508
500
509 def print_(self, printer):
501 def print_(self, printer):
510 """ Print the contents of the ConsoleWidget to the specified QPrinter.
502 """ Print the contents of the ConsoleWidget to the specified QPrinter.
@@ -1360,14 +1352,13 b' class ConsoleWidget(Configurable, QtGui.QWidget):'
1360 cursor.insertText(text)
1352 cursor.insertText(text)
1361 cursor.endEditBlock()
1353 cursor.endEditBlock()
1362
1354
1363 def _insert_plain_text_into_buffer(self, text):
1355 def _insert_plain_text_into_buffer(self, cursor, text):
1364 """ Inserts text into the input buffer at the current cursor position,
1356 """ Inserts text into the input buffer using the specified cursor (which
1365 ensuring that continuation prompts are inserted as necessary.
1357 must be in the input buffer), ensuring that continuation prompts are
1358 inserted as necessary.
1366 """
1359 """
1367 lines = unicode(text).splitlines(True)
1360 lines = unicode(text).splitlines(True)
1368 if lines:
1361 if lines:
1369 self._keep_cursor_in_buffer()
1370 cursor = self._control.textCursor()
1371 cursor.beginEditBlock()
1362 cursor.beginEditBlock()
1372 cursor.insertText(lines[0])
1363 cursor.insertText(lines[0])
1373 for line in lines[1:]:
1364 for line in lines[1:]:
@@ -1379,7 +1370,6 b' class ConsoleWidget(Configurable, QtGui.QWidget):'
1379 cursor, self._continuation_prompt_html)
1370 cursor, self._continuation_prompt_html)
1380 cursor.insertText(line)
1371 cursor.insertText(line)
1381 cursor.endEditBlock()
1372 cursor.endEditBlock()
1382 self._control.setTextCursor(cursor)
1383
1373
1384 def _in_buffer(self, position=None):
1374 def _in_buffer(self, position=None):
1385 """ Returns whether the current cursor (or, if specified, a position) is
1375 """ Returns whether the current cursor (or, if specified, a position) is
General Comments 0
You need to be logged in to leave comments. Login now