From 6c7335e5dbe258c5cd65e0391bceb90cd233a3c8 Mon Sep 17 00:00:00 2001 From: miruka Date: Fri, 22 May 2020 00:10:45 -0400 Subject: [PATCH] Add keybind to open links in messages Ctrl+O by default. Opens externally all links in selecteds, focused or the last message that has links. Can't open files (media events) yet. --- TODO.md | 1 + src/backend/user_files.py | 1 + src/gui/Pages/Chat/Timeline/EventList.qml | 27 +++++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/TODO.md b/TODO.md index 9506c8da..695a26ca 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,6 @@ # TODO +- `i <= 1000` resp - highlight messages being responded to - highlight messages with mention - add room members loading indicator diff --git a/src/backend/user_files.py b/src/backend/user_files.py index a24279c6..40fe18d7 100644 --- a/src/backend/user_files.py +++ b/src/backend/user_files.py @@ -324,6 +324,7 @@ class UISettings(JSONDataFile): "removeFocusedOrSelectedMessages": ["Ctrl+R", "Alt+Del"], "replyToFocusedOrLastMessage": ["Ctrl+Q"], # Q for Quote "debugFocusedMessage": ["Ctrl+Shift+D"], + "openMessagesLinks": ["Ctrl+O"], "clearRoomMessages": ["Ctrl+L"], "sendFile": ["Alt+S"], diff --git a/src/gui/Pages/Chat/Timeline/EventList.qml b/src/gui/Pages/Chat/Timeline/EventList.qml index ce9a02e1..214e1be5 100644 --- a/src/gui/Pages/Chat/Timeline/EventList.qml +++ b/src/gui/Pages/Chat/Timeline/EventList.qml @@ -125,6 +125,33 @@ Rectangle { } } + HShortcut { + sequences: window.settings.keys.openMessagesLinks + onActivated: { + let events = [] + + if (eventList.selectedCount) { + events = eventList.getSortedChecked() + } else if (eventList.currentIndex !== -1) { + events = [eventList.model.get(eventList.currentIndex)] + } else { + // Find most recent event containing links + for (let i = 0; i < eventList.model.count && i <= 1000; i++) { + const ev = eventList.model.get(i) + + if (JSON.parse(ev.links).length) { + events = [ev] + break + } + } + } + + for (const event of events) { + for (const link of JSON.parse(event.links)) + Qt.openUrlExternally(link) + } + } + } HShortcut { active: eventList.currentItem