슬래시 방향키 순환 계산 분리
This commit is contained in:
@@ -291,6 +291,34 @@ export const clampSlashHighlightedIndex = (currentIndex, commandCount) => {
|
||||
return Math.min(index, count - 1)
|
||||
}
|
||||
|
||||
/**
|
||||
* 슬래시 메뉴 방향키 탐색 후 하이라이트 인덱스를 계산한다.
|
||||
* @param {Object} options - 계산 옵션
|
||||
* @param {number} options.currentIndex - 현재 하이라이트 인덱스
|
||||
* @param {number} options.commandCount - 표시 가능한 명령 개수
|
||||
* @param {string} options.key - 누른 키
|
||||
* @returns {number} 다음 하이라이트 인덱스
|
||||
*/
|
||||
export const getNextSlashHighlightedIndex = ({ currentIndex, commandCount, key }) => {
|
||||
const count = Math.max(0, Number.isFinite(commandCount) ? Math.floor(commandCount) : 0)
|
||||
|
||||
if (count <= 0) {
|
||||
return 0
|
||||
}
|
||||
|
||||
const index = clampSlashHighlightedIndex(currentIndex, count)
|
||||
|
||||
if (key === 'ArrowDown') {
|
||||
return (index + 1) % count
|
||||
}
|
||||
|
||||
if (key === 'ArrowUp') {
|
||||
return (index - 1 + count) % count
|
||||
}
|
||||
|
||||
return index
|
||||
}
|
||||
|
||||
/**
|
||||
* 라이브 모드 미디어 슬래시 명령 처리 중 지연 commit을 무시할지 확인한다.
|
||||
* @param {Object} options - 판별 옵션
|
||||
|
||||
Reference in New Issue
Block a user