Skip to content
Permalink
Browse files

[pyqgis-console] improving to auto closing bracket

  • Loading branch information
slarosa committed Jun 11, 2013
1 parent 12fcea1 commit 1bfa97091c430d201d63255ff807b16dede67e53
Showing with 27 additions and 4 deletions.
  1. +19 −2 python/console/console_editor.py
  2. +8 −2 python/console/console_sci.py
@@ -643,12 +643,29 @@ def syntaxCheck(self, filename=None, fromContextMenu=True):

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
@@ -349,7 +349,7 @@ def showNext(self):
#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 @@ def keyPressEvent(self, e):
## 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):

0 comments on commit 1bfa970

Please sign in to comment.
You can’t perform that action at this time.