mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-18 00:03:05 -04:00
[pyqgis-console][fix #8392] automatically removes the redundant char when autoclosing brackets option is enabled
This commit is contained in:
parent
e95672e06d
commit
3644402bc7
@ -649,7 +649,7 @@ class Editor(QsciScintilla):
|
|||||||
|
|
||||||
def keyPressEvent(self, e):
|
def keyPressEvent(self, e):
|
||||||
if self.settings.value("pythonConsole/autoCloseBracketEditor", True, type=bool):
|
if self.settings.value("pythonConsole/autoCloseBracketEditor", True, type=bool):
|
||||||
startLine, _, endLine, _ = self.getSelection()
|
startLine, _, endLine, endPos = self.getSelection()
|
||||||
t = unicode(e.text())
|
t = unicode(e.text())
|
||||||
## Close bracket automatically
|
## Close bracket automatically
|
||||||
if t in self.opening:
|
if t in self.opening:
|
||||||
@ -660,6 +660,7 @@ class Editor(QsciScintilla):
|
|||||||
self.removeSelectedText()
|
self.removeSelectedText()
|
||||||
if startLine == endLine:
|
if startLine == endLine:
|
||||||
self.insert(self.opening[i] + selText + self.closing[i])
|
self.insert(self.opening[i] + selText + self.closing[i])
|
||||||
|
self.setCursorPosition(endLine, endPos+2)
|
||||||
return
|
return
|
||||||
elif startLine < endLine and self.opening[i] in ("'", '"'):
|
elif startLine < endLine and self.opening[i] in ("'", '"'):
|
||||||
self.insert("'''" + selText + "'''")
|
self.insert("'''" + selText + "'''")
|
||||||
@ -669,6 +670,17 @@ class Editor(QsciScintilla):
|
|||||||
self.endUndoAction()
|
self.endUndoAction()
|
||||||
else:
|
else:
|
||||||
self.insert(self.closing[i])
|
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)
|
QsciScintilla.keyPressEvent(self, e)
|
||||||
else:
|
else:
|
||||||
QsciScintilla.keyPressEvent(self, e)
|
QsciScintilla.keyPressEvent(self, e)
|
||||||
|
@ -352,7 +352,7 @@ class ShellScintilla(QsciScintilla, code.InteractiveInterpreter):
|
|||||||
#self.SendScintilla(QsciScintilla.SCI_DELETEBACK)
|
#self.SendScintilla(QsciScintilla.SCI_DELETEBACK)
|
||||||
|
|
||||||
def keyPressEvent(self, e):
|
def keyPressEvent(self, e):
|
||||||
startLine, startPos, endLine, _ = self.getSelection()
|
startLine, startPos, endLine, endPos = self.getSelection()
|
||||||
|
|
||||||
# handle invalid cursor position and multiline selections
|
# handle invalid cursor position and multiline selections
|
||||||
if not self.is_cursor_on_edition_zone() or startLine < endLine:
|
if not self.is_cursor_on_edition_zone() or startLine < endLine:
|
||||||
@ -418,9 +418,21 @@ class ShellScintilla(QsciScintilla, code.InteractiveInterpreter):
|
|||||||
selText = self.selectedText()
|
selText = self.selectedText()
|
||||||
self.removeSelectedText()
|
self.removeSelectedText()
|
||||||
self.insert(self.opening[i] + selText + self.closing[i])
|
self.insert(self.opening[i] + selText + self.closing[i])
|
||||||
|
self.setCursorPosition(endLine, endPos+2)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
self.insert(self.closing[i])
|
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)
|
QsciScintilla.keyPressEvent(self, e)
|
||||||
|
|
||||||
def contextMenuEvent(self, e):
|
def contextMenuEvent(self, e):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user