[pyqgis-console][fix #8392] automatically removes the redundant char when autoclosing brackets option is enabled

This commit is contained in:
Salvatore Larosa 2013-08-02 15:41:19 +02:00
parent e95672e06d
commit 3644402bc7
2 changed files with 26 additions and 2 deletions

View File

@ -649,7 +649,7 @@ class Editor(QsciScintilla):
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 @@ class Editor(QsciScintilla):
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 @@ class Editor(QsciScintilla):
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)

View File

@ -352,7 +352,7 @@ class ShellScintilla(QsciScintilla, code.InteractiveInterpreter):
#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 @@ class ShellScintilla(QsciScintilla, code.InteractiveInterpreter):
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):