Skip to content

Commit

Permalink
[python console] Improve key up/down press for multiline command string
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Jun 3, 2020
1 parent d9dd2bf commit 2a25c18
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions python/console/console_sci.py
Expand Up @@ -299,11 +299,22 @@ def get_end_pos(self):
line = self.lines() - 1
return line, len(self.text(line))

def is_cursor_at_start(self):
"""Return True if cursor is at the end of text"""
cline, cindex = self.getCursorPosition()
return cline == 0 and cindex == 0

def is_cursor_at_end(self):
"""Return True if cursor is at the end of text"""
cline, cindex = self.getCursorPosition()
return (cline, cindex) == self.get_end_pos()

def move_cursor_to_start(self):
"""Move cursor to start of text"""
self.setCursorPosition(0, 0)
self.ensureCursorVisible()
self.ensureLineVisible(0)

def move_cursor_to_end(self):
"""Move cursor to end of text"""
line, index = self.get_end_pos()
Expand Down Expand Up @@ -405,7 +416,7 @@ def showNext(self):
self.setText("")
else:
self.setText(self.history[self.historyIndex])
self.move_cursor_to_end()
self.move_cursor_to_start()
# self.SendScintilla(QsciScintilla.SCI_DELETEBACK)

def keyPressEvent(self, e):
Expand Down Expand Up @@ -458,9 +469,17 @@ def keyPressEvent(self, e):
e.accept()

elif e.key() == Qt.Key_Down and not self.isListActive():
self.showPrevious()
if self.is_cursor_at_end():
self.showPrevious()
else:
QsciScintilla.keyPressEvent(self, e)

elif e.key() == Qt.Key_Up and not self.isListActive():
self.showNext()
if self.is_cursor_at_start():
self.showNext()
else:
QsciScintilla.keyPressEvent(self, e)

# TODO: press event for auto-completion file directory
else:
t = e.text()
Expand Down

0 comments on commit 2a25c18

Please sign in to comment.