Skip to content
Permalink
Browse files
[pyqgis-console][fix #8392] automatically removes the redundant char …
…when autoclosing brackets option is enabled
  • Loading branch information
slarosa committed Aug 2, 2013
1 parent e95672e commit 3644402bc770821442f84054e0e21367d279aad9
Showing with 26 additions and 2 deletions.
  1. +13 −1 python/console/console_editor.py
  2. +13 −1 python/console/console_sci.py
@@ -649,7 +649,7 @@ def syntaxCheck(self, filename=None, fromContextMenu=True):

def keyPressEvent(self, e):
if self.settings.value("pythonConsole/autoCloseBracketEditor", True, type=bool):
startLine, _, endLine, _ = self.getSelection()
startLine, _, endLine, endPos = self.getSelection()
t = unicode(e.text())
## Close bracket automatically
if t in self.opening:
@@ -660,6 +660,7 @@ def keyPressEvent(self, e):
self.removeSelectedText()
if startLine == endLine:
self.insert(self.opening[i] + selText + self.closing[i])
self.setCursorPosition(endLine, endPos+2)
return
elif startLine < endLine and self.opening[i] in ("'", '"'):
self.insert("'''" + selText + "'''")
@@ -669,6 +670,17 @@ def keyPressEvent(self, e):
self.endUndoAction()
else:
self.insert(self.closing[i])
## FIXES #8392 (automatically removes the redundant char
## when autoclosing brackets option is enabled)
if t in self.closing:
l, pos = self.getCursorPosition()
txt = self.text(l)
try:
if txt[pos-1] in self.opening:
self.setCursorPosition(l, pos+1)
self.SendScintilla(QsciScintilla.SCI_DELETEBACK)
except IndexError:
pass
QsciScintilla.keyPressEvent(self, e)
else:
QsciScintilla.keyPressEvent(self, e)
@@ -352,7 +352,7 @@ def showNext(self):
#self.SendScintilla(QsciScintilla.SCI_DELETEBACK)

def keyPressEvent(self, e):
startLine, startPos, endLine, _ = self.getSelection()
startLine, startPos, endLine, endPos = self.getSelection()

# handle invalid cursor position and multiline selections
if not self.is_cursor_on_edition_zone() or startLine < endLine:
@@ -418,9 +418,21 @@ def keyPressEvent(self, e):
selText = self.selectedText()
self.removeSelectedText()
self.insert(self.opening[i] + selText + self.closing[i])
self.setCursorPosition(endLine, endPos+2)
return
else:
self.insert(self.closing[i])
## FIXES #8392 (automatically removes the redundant char
## when autoclosing brackets option is enabled)
if t in self.closing:
l, pos = self.getCursorPosition()
txt = self.text(l)
try:
if txt[pos-1] in self.opening:
self.setCursorPosition(l, pos+1)
self.SendScintilla(QsciScintilla.SCI_DELETEBACK)
except IndexError:
pass
QsciScintilla.keyPressEvent(self, e)

def contextMenuEvent(self, e):

0 comments on commit 3644402

Please sign in to comment.