This commit is contained in:
kenjiding 2025-04-26 20:24:19 +09:00 committed by GitHub
commit a828ffd52d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -147,6 +147,22 @@ export const SearchMenu = () => {
} }
}; };
const fixInputCursorPosition = () => {
requestAnimationFrame(() => {
const searchInput = searchInputRef.current;
const isFocus = document.activeElement === searchInput;
// if input is not focus and input instance is not exist return
if (!searchInput || !isFocus) {
return;
}
const cursorPosition = searchInput.selectionStart;
const textLength = searchInput.value.length!;
if (cursorPosition !== textLength) {
searchInput.setSelectionRange(textLength, textLength);
}
});
};
useEffect(() => { useEffect(() => {
setAppState((state) => { setAppState((state) => {
return { return {
@ -292,6 +308,7 @@ export const SearchMenu = () => {
if (event.key === KEYS.ARROW_UP) { if (event.key === KEYS.ARROW_UP) {
event.stopPropagation(); event.stopPropagation();
stableState.goToPreviousItem(); stableState.goToPreviousItem();
fixInputCursorPosition();
} else if (event.key === KEYS.ARROW_DOWN) { } else if (event.key === KEYS.ARROW_DOWN) {
event.stopPropagation(); event.stopPropagation();
stableState.goToNextItem(); stableState.goToNextItem();