Add keyboard controls for message focus/selection

This commit is contained in:
miruka 2020-03-27 04:49:01 -04:00
parent 6ca10e1f2b
commit 936c49127d
5 changed files with 81 additions and 8 deletions

View File

@ -270,8 +270,14 @@ class UISettings(JSONDataFile):
"10": "Alt+0",
},
"unselectAllMessages": ["Escape"],
"unfocusOrUnselectAllMessages": ["Escape"],
"focusPreviousMessage": ["Ctrl+Up", "Ctrl+K"],
"focusNextMessage": ["Ctrl+Down", "Ctrl+J"],
"toggleSelectMessage": ["Ctrl+Space"],
"selectMessagesUntilHere": ["Ctrl+Shift+Space"],
"debugFocusedMessage": ["Ctrl+D"],
"clearRoomMessages": ["Ctrl+L"],
"sendFile": ["Alt+S"],
"sendFileFromPathInClipboard": ["Alt+Shift+S"],

View File

@ -77,14 +77,12 @@ ListView {
function delegatesChecked(...indices) {
print( indices)
for (const i of indices) {
const model = listView.model.get(i)
checkedDelegates[model.id] = model
}
lastCheckedDelegateIndex = indices.slice(-1)[0]
checkedDelegatesChanged()
}
@ -98,6 +96,27 @@ ListView {
const model = listView.model.get(i)
delete checkedDelegates[model.id]
}
checkedDelegatesChanged()
}
function toggleCheck(...indices) {
const checkedIndices = []
for (const i of indices) {
const model = listView.model.get(i)
if (model.id in checkedDelegates) {
delete checkedDelegates[model.id]
} else {
checkedDelegates[model.id] = model
checkedIndices.push(i)
}
}
if (checkedIndices.length > 0)
lastCheckedDelegateIndex = checkedIndices.slice(-1)[0]
checkedDelegatesChanged()
}

View File

@ -205,7 +205,8 @@ Rectangle {
if (ev.matches(StandardKey.Copy) &&
! area.selectedText &&
eventList &&
eventList.selectedCount) {
(eventList.selectedCount ||
eventList.currentIndex !== -1)) {
ev.accepted = true
eventList.copySelectedDelegates()

View File

@ -57,6 +57,8 @@ HColumnLayout {
combine ? theme.spacing / (compact ? 4 : 2) :
theme.spacing * (compact ? 1 : 2)
readonly property alias eventContent: eventContent
// Needed because of eventList's MouseArea which steals the
// HSelectableLabel's MouseArea hover events
onCursorShapeChanged: eventList.cursorShape = cursorShape
@ -209,7 +211,7 @@ HColumnLayout {
qsTr("Copy text")
onTriggered: {
if (! eventList.selectedCount) {
if (! eventList.selectedCount && eventList.currentItem === -1){
Clipboard.text = JSON.parse(model.source).body
return
}

View File

@ -15,13 +15,51 @@ Rectangle {
HShortcut {
sequences: window.settings.keys.unselectAllMessages
onActivated: eventList.checkedDelegates = {}
sequences: window.settings.keys.unfocusOrUnselectAllMessages
onActivated: {
eventList.currentIndex !== -1 ?
eventList.currentIndex = -1 :
eventList.checkedDelegates = {}
}
}
HShortcut {
sequences: window.settings.keys.focusPreviousMessage
onActivated: eventList.incrementCurrentIndex()
}
HShortcut {
sequences: window.settings.keys.focusNextMessage
onActivated:
eventList.currentIndex === 0 ?
eventList.currentIndex = -1 :
eventList.decrementCurrentIndex()
}
HShortcut {
enabled: eventList.currentItem
sequences: window.settings.keys.toggleSelectMessage
onActivated: eventList.toggleCheck(eventList.currentIndex)
}
HShortcut {
enabled: eventList.currentItem
sequences: window.settings.keys.selectMessagesUntilHere
onActivated:
eventList.delegatesFromLastToHereChecked(eventList.currentIndex)
}
HShortcut {
enabled: eventList.currentItem
sequences: window.settings.keys.debugFocusedMessage
onActivated:
eventList.currentItem.eventContent.debugConsoleLoader.toggle()
}
HListView {
id: eventList
clip: true
keyNavigationWraps: false
anchors.fill: parent
anchors.leftMargin: theme.spacing
@ -87,6 +125,13 @@ Rectangle {
return
}
if (! eventList.selectedCount && eventList.currentIndex !== -1) {
Clipboard.text = JSON.parse(
eventList.model.get(eventList.currentIndex).source
).body
return
}
const contents = []
for (const model of eventList.getSortedCheckedDelegates()) {