Skip to content

Commit

Permalink
[python console] Deal with remaining vanishing prompt scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Jun 3, 2020
1 parent bbdc906 commit af474ea
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions python/console/console_sci.py
Expand Up @@ -454,6 +454,7 @@ def keyPressEvent(self, e):

line, index = self.getCursorPosition()
cmd = self.text(line)
hasSelectedText = self.hasSelectedText()

if e.key() in (Qt.Key_Return, Qt.Key_Enter) and not self.isListActive():
self.entered()
Expand Down Expand Up @@ -481,13 +482,11 @@ def keyPressEvent(self, e):
self.showNext()
else:
QsciScintilla.keyPressEvent(self, e)

# TODO: press event for auto-completion file directory
else:
t = e.text()
self.autoCloseBracket = self.settings.value("pythonConsole/autoCloseBracket", False, type=bool)
self.autoImport = self.settings.value("pythonConsole/autoInsertionImport", True, type=bool)
txt = cmd[:index].replace('>>> ', '').replace('... ', '')
# Close bracket automatically
if t in self.opening and self.autoCloseBracket:
i = self.opening.index(t)
Expand All @@ -497,28 +496,30 @@ def keyPressEvent(self, e):
self.insert(self.opening[i] + selText + self.closing[i])
self.setCursorPosition(endLine, endPos + 2)
return
elif t == '(' and (re.match(r'^[ \t]*def \w+$', txt)
or re.match(r'^[ \t]*class \w+$', txt)):
elif t == '(' and (re.match(r'^[ \t]*def \w+$', cmd)
or re.match(r'^[ \t]*class \w+$', cmd)):
self.insert('):')
else:
self.insert(self.closing[i])
# FIXES #8392 (automatically removes the redundant char
# when autoclosing brackets option is enabled)
elif t in [')', ']', '}'] and self.autoCloseBracket:
txt = self.text(line)
try:
if txt[index - 1] in self.opening and t == txt[index]:
if cmd[index - 1] in self.opening and t == cmd[index]:
self.setCursorPosition(line, index + 1)
self.SendScintilla(QsciScintilla.SCI_DELETEBACK)
except IndexError:
pass
elif t == ' ' and self.autoImport:
ptrn = r'^[ \t]*from [\w.]+$'
if re.match(ptrn, txt):
if re.match(ptrn, cmd):
self.insert(' import')
self.setCursorPosition(line, index + 7)
QsciScintilla.keyPressEvent(self, e)

if len(self.text(0)) == 0 or hasSelectedText:
self.displayPrompt(False)

def contextMenuEvent(self, e):
menu = QMenu(self)
subMenu = QMenu(menu)
Expand Down

0 comments on commit af474ea

Please sign in to comment.