mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-04 00:06:46 -05:00
[pyqgis-console] improving to auto closing bracket
This commit is contained in:
parent
12fcea167a
commit
1bfa97091c
@ -643,12 +643,29 @@ class Editor(QsciScintilla):
|
||||
|
||||
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 @@ class ShellScintilla(QsciScintilla, code.InteractiveInterpreter):
|
||||
#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 @@ class ShellScintilla(QsciScintilla, code.InteractiveInterpreter):
|
||||
## 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):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user