Skip to content

Commit

Permalink
[pyqgis-console][fix #8392] automatically removes the redundant char …
Browse files Browse the repository at this point in the history
…when autoclosing brackets option is enabled
  • Loading branch information
slarosa committed Aug 2, 2013
1 parent e95672e commit 3644402
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
14 changes: 13 additions & 1 deletion python/console/console_editor.py
Expand Up @@ -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:
Expand All @@ -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 + "'''")
Expand All @@ -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)
Expand Down
14 changes: 13 additions & 1 deletion python/console/console_sci.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 3644402

Please sign in to comment.