fix: HOTFIX useHistory currentIndex more than MAX_HISTORY_LENGTH cause replace fail (#8819)

fix: useHistory currentIndex more than MAX_HISTORY_LENGTH cause replace fail
This commit is contained in:
TomIsion 2025-11-21 02:19:20 +08:00 • committed by GitHub
parent 74b1f73a87
commit 7787685f12
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -54,7 +54,7 @@ export function useInputHistory(historyKey: string) {
return;
}
setCurrentIndex(inputHistory.length + 1);
setCurrentIndex(Math.min(inputHistory.length + 1, MAX_HISTORY_LENGTH));
setInputHistory((prev) => {
return [...prev, inputValue].slice(-MAX_HISTORY_LENGTH);
});