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", "10": "Alt+0",
}, },
"unselectAllMessages": ["Escape"], "unfocusOrUnselectAllMessages": ["Escape"],
"clearRoomMessages": ["Ctrl+L"], "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"], "sendFile": ["Alt+S"],
"sendFileFromPathInClipboard": ["Alt+Shift+S"], "sendFileFromPathInClipboard": ["Alt+Shift+S"],

View File

@ -77,14 +77,12 @@ ListView {
function delegatesChecked(...indices) { function delegatesChecked(...indices) {
print( indices)
for (const i of indices) { for (const i of indices) {
const model = listView.model.get(i) const model = listView.model.get(i)
checkedDelegates[model.id] = model checkedDelegates[model.id] = model
} }
lastCheckedDelegateIndex = indices.slice(-1)[0] lastCheckedDelegateIndex = indices.slice(-1)[0]
checkedDelegatesChanged() checkedDelegatesChanged()
} }
@ -98,6 +96,27 @@ ListView {
const model = listView.model.get(i) const model = listView.model.get(i)
delete checkedDelegates[model.id] 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() checkedDelegatesChanged()
} }

View File

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

View File

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

View File

@ -15,13 +15,51 @@ Rectangle {
HShortcut { HShortcut {
sequences: window.settings.keys.unselectAllMessages sequences: window.settings.keys.unfocusOrUnselectAllMessages
onActivated: eventList.checkedDelegates = {} 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 { HListView {
id: eventList id: eventList
clip: true clip: true
keyNavigationWraps: false
anchors.fill: parent anchors.fill: parent
anchors.leftMargin: theme.spacing anchors.leftMargin: theme.spacing
@ -87,6 +125,13 @@ Rectangle {
return return
} }
if (! eventList.selectedCount && eventList.currentIndex !== -1) {
Clipboard.text = JSON.parse(
eventList.model.get(eventList.currentIndex).source
).body
return
}
const contents = [] const contents = []
for (const model of eventList.getSortedCheckedDelegates()) { for (const model of eventList.getSortedCheckedDelegates()) {