Skip to content

Commit

Permalink
Bug Fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
jason5ng32 committed Dec 15, 2023
1 parent 1d0eca4 commit 5c76810
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions public/res/shortcut.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const navigateCards = (direction) => {
if (currentIndex !== -1) {
cards[currentIndex].classList.remove('hover', 'keyboard-hover');
cards[currentIndex].removeAttribute('data-keyboard-hover');
cards[currentIndex].blur();
} else {
currentIndex = 0; // 如果没有卡片高亮,则从第一张卡片开始
}
Expand All @@ -52,7 +51,6 @@ const navigateCards = (direction) => {
const currentCard = cards[currentIndex];
currentCard.classList.add('keyboard-hover');
currentCard.setAttribute('data-keyboard-hover', 'true');
currentCard.focus();

const cardTop = currentCard.getBoundingClientRect().top + window.pageYOffset;
window.scrollTo({ top: cardTop - 60, behavior: 'smooth' });
Expand All @@ -62,10 +60,16 @@ const navigateCards = (direction) => {

document.addEventListener(
"keydown",
({ key, target, metaKey, altKey, ctrlKey }) => {
(event) => {
const { key, target, metaKey, altKey, ctrlKey } = event;

if (target.tagName === "INPUT") return;
if (metaKey || altKey || ctrlKey) return;

if (key === 'j' || key === 'k') {
event.preventDefault(); // 阻止 'j' 和 'k' 的默认焦点行为
}

keyPool += ignoreKeys.includes(key) ? "" : key;
timer && clearTimeout(timer);
timer = setTimeout(() => {
Expand Down

0 comments on commit 5c76810

Please sign in to comment.