Add visited pages history back/forward keys (#204)
* Add keys for back and forward through history Move through history of visited rooms without altering it. Ctrl+H and Ctrl+Y by default. Deviating from history while in the middle of it causes a part of history to be discarded. * Change default history binding to Ctrl+H and Ctrl+Shift+H * Rename functions and settings `earlier_page` and `later_page` is consistent naming with `last_page` * Add option to wrap history If you press `later_page` while at index 0 (newest), you loop to the end of recorded history (oldest). If you press `earlier_page` while at at the end of history (oldest), you loop back to the top (newest). This can be disabled. * Add showNthFromHistory Grouped duplicated code into a new funcion. * Minor formatting changes * Move wrap_history setting from to General section The Keys section is purely for keybindings; this setting should also be able to control history navigation not done by keyboard such as extra mouse button bindings. * Change default bind for later_page and clear_all Ctrl+H and Ctrl+L are a more intuitive pair than Ctrl+H and Ctrl+Shift+H. Meanwhile, clear_all does not need the accessible binding Ctrl+L. Co-authored-by: miruka <miruka@disroot.org>
This commit is contained in:
parent
f88ab45b94
commit
c140d69138
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user