Merge pull request #684 from flagist0/select-note-type-with-ctrl-plus-digit-key

Allow to choose note type from list by pressing ctrl + row number
This commit is contained in:
Damien Elmes 2020-07-13 21:23:35 +10:00 committed by GitHub
commit c3800b6f9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 13 deletions

View file

@ -42,6 +42,7 @@ kenden
Nickolay Yudin <kelciour@gmail.com> Nickolay Yudin <kelciour@gmail.com>
neitrinoweb <github.com/neitrinoweb/> neitrinoweb <github.com/neitrinoweb/>
Andreas Reis <github.com/rathsky> Andreas Reis <github.com/rathsky>
Alexander Presnyakov <flagist0@gmail.com>
******************** ********************
The text of the 3 clause BSD license follows: The text of the 3 clause BSD license follows:

View file

@ -77,19 +77,23 @@ class StudyDeck(QDialog):
def eventFilter(self, obj: QObject, evt: QEvent) -> bool: def eventFilter(self, obj: QObject, evt: QEvent) -> bool:
if evt.type() == QEvent.KeyPress: if evt.type() == QEvent.KeyPress:
if evt.key() == Qt.Key_Up: new_row = current_row = self.form.list.currentRow()
c = self.form.list.count() rows_count = self.form.list.count()
row = self.form.list.currentRow() - 1 key = evt.key()
if row < 0:
row = c - 1 if key == Qt.Key_Up:
self.form.list.setCurrentRow(row) new_row = current_row - 1
return True elif key == Qt.Key_Down:
elif evt.key() == Qt.Key_Down: new_row = current_row + 1
c = self.form.list.count() elif evt.modifiers() & Qt.ControlModifier and Qt.Key_1 <= key <= Qt.Key_9:
row = self.form.list.currentRow() + 1 row_index = key - Qt.Key_1
if row == c: if row_index < rows_count:
row = 0 new_row = row_index
self.form.list.setCurrentRow(row)
if rows_count:
new_row %= rows_count # don't let row index overflow/underflow
if new_row != current_row:
self.form.list.setCurrentRow(new_row)
return True return True
return False return False