refac: command arrow up/down behaviour

This commit is contained in:
Timothy Jaeryang Baek
2025-05-16 15:39:26 +04:00
parent c201b4d689
commit 62180b15e1
4 changed files with 35 additions and 14 deletions

View File

@@ -878,20 +878,38 @@
e.preventDefault();
commandsElement.selectUp();
const container = document.getElementById('command-options-container');
const commandOptionButton = [
...document.getElementsByClassName('selected-command-option-button')
]?.at(-1);
commandOptionButton.scrollIntoView({ block: 'center' });
if (commandOptionButton && container) {
const elTop = commandOptionButton.offsetTop;
const elHeight = commandOptionButton.offsetHeight;
const containerHeight = container.clientHeight;
// Center the selected button in the container
container.scrollTop = elTop - containerHeight / 2 + elHeight / 2;
}
}
if (commandsContainerElement && e.key === 'ArrowDown') {
e.preventDefault();
commandsElement.selectDown();
const container = document.getElementById('command-options-container');
const commandOptionButton = [
...document.getElementsByClassName('selected-command-option-button')
]?.at(-1);
commandOptionButton.scrollIntoView({ block: 'center' });
if (commandOptionButton && container) {
const elTop = commandOptionButton.offsetTop;
const elHeight = commandOptionButton.offsetHeight;
const containerHeight = container.clientHeight;
// Center the selected button in the container
container.scrollTop = elTop - containerHeight / 2 + elHeight / 2;
}
}
if (commandsContainerElement && e.key === 'Enter') {