[pyqgis-console] improving to auto closing bracket

This commit is contained in:
Salvatore Larosa 2013-06-11 19:07:16 +02:00
parent 12fcea167a
commit 1bfa97091c
2 changed files with 27 additions and 4 deletions

View File

@ -643,12 +643,29 @@ class Editor(QsciScintilla):
def keyPressEvent(self, e):
if self.settings.value("pythonConsole/autoCloseBracketEditor", True, type=bool):
startLine, _, endLine, _ = self.getSelection()
t = unicode(e.text())
## Close bracket automatically
if t in self.opening:
i = self.opening.index(t)
self.insert(self.closing[i])
QsciScintilla.keyPressEvent(self, e)
if self.hasSelectedText():
self.beginUndoAction()
selText = self.selectedText()
self.removeSelectedText()
if startLine == endLine:
self.insert(self.opening[i] + selText + self.closing[i])
return
elif startLine < endLine and self.opening[i] in ("'", '"'):
self.insert("'''" + selText + "'''")
return
else:
self.insert(self.closing[i])
self.endUndoAction()
else:
self.insert(self.closing[i])
QsciScintilla.keyPressEvent(self, e)
else:
QsciScintilla.keyPressEvent(self, e)
def focusInEvent(self, e):
pathfile = self.parent.path

View File

@ -349,7 +349,7 @@ class ShellScintilla(QsciScintilla, code.InteractiveInterpreter):
#self.SendScintilla(QsciScintilla.SCI_DELETEBACK)
def keyPressEvent(self, e):
startLine, _, endLine, _ = self.getSelection()
startLine, startPos, endLine, _ = self.getSelection()
# handle invalid cursor position and multiline selections
if not self.is_cursor_on_edition_zone() or startLine < endLine:
@ -411,7 +411,13 @@ class ShellScintilla(QsciScintilla, code.InteractiveInterpreter):
## Close bracket automatically
if t in self.opening:
i = self.opening.index(t)
self.insert(self.closing[i])
if self.hasSelectedText() and startPos != 0:
selText = self.selectedText()
self.removeSelectedText()
self.insert(self.opening[i] + selText + self.closing[i])
return
else:
self.insert(self.closing[i])
QsciScintilla.keyPressEvent(self, e)
def contextMenuEvent(self, e):