diff --git a/src/config/settings.py b/src/config/settings.py index e362f395..d1c7f894 100644 --- a/src/config/settings.py +++ b/src/config/settings.py @@ -17,6 +17,10 @@ class General: # right room pane is visible at a time. hide_side_panes_under: int = 450 + # Whether to wrap around or do nothing when using the earlier_page or + # later_page keybinds and reaching the start or end of the history. + wrap_history: bool = True + # How many seconds the cursor must hover on buttons and other elements # to show tooltips. tooltips_delay: float = 0.5 @@ -253,6 +257,11 @@ class Keys: # Switch to the last opened page/chat, similar to Alt+Tab on most desktops. last_page = ["Ctrl+Tab"] + # Go throgh history of opened chats, + # similar to the "page back" and "page forward" keys in web browsers + earlier_page = ["Ctrl+H"] + later_page = ["Ctrl+L"] + # Toggle muting all notifications in the running client, # except highlights (e.g. replies or keywords) notifications_highlights_only = ["Ctrl+Alt+H"] @@ -453,7 +462,7 @@ class Keys: # Clear all messages from the chat. # This does not remove anything for other users. - clear_all = ["Ctrl+L"] + clear_all = ["Ctrl+Shift+L"] class ImageViewer: # Close the image viewer. Escape can also be used. diff --git a/src/gui/PageLoader.qml b/src/gui/PageLoader.qml index 347f561c..60306cf5 100644 --- a/src/gui/PageLoader.qml +++ b/src/gui/PageLoader.qml @@ -15,6 +15,7 @@ HLoader { // List of previously loaded [componentUrl, {properties}] property var history: [] property int historyLength: 20 + property int historyPosition: 0 readonly property alias appearAnimation: appearAnimation @@ -22,9 +23,18 @@ HLoader { signal recycled() signal previousShown(string componentUrl, var properties) - function show(componentUrl, properties={}) { - history.unshift([componentUrl, properties]) - if (history.length > historyLength) history.pop() + function show(componentUrl, properties={}, alterHistory=true) { + if (alterHistory) { + // A new branch of history will be added. + // The new branch replaces everything after the current point. + while (historyPosition > 0) { + history.shift() + historyPosition-- + } + // Add entry to history + history.unshift([componentUrl, properties]) + if (history.length > historyLength) history.pop() + } const recycle = window.uiState.page === componentUrl && @@ -51,13 +61,37 @@ HLoader { show("Pages/Chat/Chat.qml", {userRoomId: [userId, roomId]}) } + function showNthFromHistory(n, alterHistory=true) { + const [componentUrl, properties] = history[n] + show(componentUrl, properties, alterHistory) + previousShown(componentUrl, properties) + } + function showPrevious(timesBack=1) { timesBack = Math.min(timesBack, history.length - 1) if (timesBack < 1) return false - const [componentUrl, properties] = history[timesBack] - show(componentUrl, properties) - previousShown(componentUrl, properties) + showNthFromHistory(timesBack) + return true + } + + function moveThroughHistory(relativeMovement=1) { + if (history.length === 0) return false + + // Going beyond oldest entry in history + if (historyPosition + relativeMovement >= history.length) { + if (! window.settings.General.wrap_history) return false + relativeMovement -= history.length + + // Going beyond newest entry in history + } else if (historyPosition + relativeMovement < 0){ + if (! window.settings.General.wrap_history) return false + relativeMovement += history.length + } + + historyPosition += relativeMovement + + showNthFromHistory(historyPosition, false) return true } @@ -94,4 +128,14 @@ HLoader { sequences: window.settings.Keys.last_page onActivated: showPrevious() } + + HShortcut { + sequences: window.settings.Keys.earlier_page + onActivated: moveThroughHistory(1) + } + + HShortcut { + sequences: window.settings.Keys.later_page + onActivated: moveThroughHistory(-1) + } }