Focus center event if scrolled up when ctrl+j/k

When using the focus(Previous/Next)Message keybinds, no message is
focused and the view has been scrolled up, focus the message in the
center of the view instead of returning to the list's bottom to focus
the most recent one.
This commit is contained in:
miruka
2020-09-01 18:24:40 -04:00
parent a1b9f34958
commit b5b968db3a
2 changed files with 28 additions and 5 deletions

View File

@@ -26,15 +26,12 @@ Rectangle {
HShortcut {
sequences: window.settings.keys.focusPreviousMessage
onActivated: eventList.incrementCurrentIndex()
onActivated: eventList.focusPreviousMessage()
}
HShortcut {
sequences: window.settings.keys.focusNextMessage
onActivated:
eventList.currentIndex === 0 ?
eventList.currentIndex = -1 :
eventList.decrementCurrentIndex()
onActivated: eventList.focusNextMessage()
}
HShortcut {
@@ -244,6 +241,29 @@ Rectangle {
readonly property var redactableCheckedEvents:
getSortedChecked().filter(ev => eventList.canRedact(ev))
function focusCenterMessage() {
const previous = highlightRangeMode
highlightRangeMode = HListView.NoHighlightRange
currentIndex = indexAt(0, contentY + height / 2)
highlightRangeMode = previous
}
function focusPreviousMessage() {
currentIndex === -1 && contentY < -height - bottomMargin * 2 ?
focusCenterMessage() :
incrementCurrentIndex()
}
function focusNextMessage() {
currentIndex === -1 && contentY <= -height - bottomMargin * 2 ?
focusCenterMessage() :
eventList.currentIndex === 0 ?
eventList.currentIndex = -1 :
decrementCurrentIndex()
}
function copySelectedDelegates() {
if (eventList.selectedText) {
Clipboard.text = eventList.selectedText