[Glitch] Don't reset scroll when using hotkeys to focus columns, add hotkey 0 to scroll to top

Port 9334bd9ede to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
diondiondion
2025-11-28 17:19:23 +01:00
committed by Claire
parent 34aa825e96
commit c63393c963
4 changed files with 76 additions and 43 deletions

View File

@@ -81,7 +81,7 @@ import {
Quotes,
} from './util/async-components';
import { ColumnsContextProvider } from './util/columns_context';
import { focusColumn, getFocusedItemIndex, focusItemSibling } from './util/focusUtils';
import { focusColumn, getFocusedItemIndex, focusItemSibling, focusFirstItem } from './util/focusUtils';
import { WrappedSwitch, WrappedRoute } from './util/react_router_helpers';
// Dummy import, to make sure that <Status /> ends up in the application bundle.
@@ -495,20 +495,21 @@ class UI extends PureComponent {
};
handleHotkeyFocusColumn = e => {
focusColumn({index: e.key * 1});
focusColumn(e.key * 1);
};
handleHotkeyLoadMore = () => {
document.querySelector('.load-more')?.focus();
};
handleMoveToTop = () => {
focusFirstItem();
};
handleMoveUp = () => {
const currentItemIndex = getFocusedItemIndex();
if (currentItemIndex === -1) {
focusColumn({
index: 1,
focusItem: 'first-visible',
});
focusColumn(1);
} else {
focusItemSibling(currentItemIndex, -1);
}
@@ -517,10 +518,7 @@ class UI extends PureComponent {
handleMoveDown = () => {
const currentItemIndex = getFocusedItemIndex();
if (currentItemIndex === -1) {
focusColumn({
index: 1,
focusItem: 'first-visible',
});
focusColumn(1);
} else {
focusItemSibling(currentItemIndex, 1);
}
@@ -615,6 +613,7 @@ class UI extends PureComponent {
focusLoadMore: this.handleHotkeyLoadMore,
moveDown: this.handleMoveDown,
moveUp: this.handleMoveUp,
moveToTop: this.handleMoveToTop,
back: this.handleHotkeyBack,
goToHome: this.handleHotkeyGoToHome,
goToNotifications: this.handleHotkeyGoToNotifications,