feat: preventDefault on Enter

This commit is contained in:
neoapps-dev
2026-09-03 12:31:03 +03:00
parent 1311a55932
commit f92e1e77de
14 changed files with 27 additions and 3 deletions
+1
View File
@@ -72,6 +72,7 @@ export default function DevtoolsView() {
setFocusIndex(0);
}
} else if (e.key === "Enter") {
e.preventDefault();
if (focusIndex === BACK_BUTTON_INDEX) {
playBackSound();
setActiveView("main");
+1
View File
@@ -100,6 +100,7 @@ export default function GuidesView() {
} else if (e.key === "ArrowUp") {
setFocusIndex((p) => (p <= 0 ? BACK_BUTTON_INDEX : p - 1));
} else if (e.key === "Enter") {
e.preventDefault();
if (focusIndex === BACK_BUTTON_INDEX) {
goBack();
} else {
+3 -1
View File
@@ -135,8 +135,10 @@ const HomeView = memo(function HomeView() {
prev === null ? buttonsVal.length - 1 : prev > 0 ? prev - 1 : prev,
);
if (e.key === "ArrowLeft") onNavigateToSkin();
if (e.key === "Enter" && menuFocus !== null)
if (e.key === "Enter" && menuFocus !== null) {
e.preventDefault();
buttonsVal[menuFocus].action();
}
};
window.addEventListener("keydown", handleKey);
return () => window.removeEventListener("keydown", handleKey);
+1
View File
@@ -348,6 +348,7 @@ const LceOnlineView = memo(function LceOnlineView({
prev === null || prev <= 0 ? itemCount - 1 : prev - 1,
);
} else if (e.key === "Enter" && focusIndex !== null) {
e.preventDefault();
menuItems[focusIndex]?.onClick();
}
}
+3
View File
@@ -73,6 +73,7 @@ const ScreenshotsView = memo(function ScreenshotsView() {
playPressSound();
setDeleteConfirmFocusIndex((prev) => (prev === 0 ? 1 : 0));
} else if (e.key === "Enter") {
e.preventDefault();
if (deleteConfirmFocusIndex === 1) confirmDelete();
else {
playBackSound();
@@ -94,6 +95,7 @@ const ScreenshotsView = memo(function ScreenshotsView() {
playPressSound();
setModalFocusIndex((prev) => (prev < 2 ? prev + 1 : 0));
} else if (e.key === "Enter") {
e.preventDefault();
if (modalFocusIndex === 0) handleOpenFolder(selectedScreenshot);
else if (modalFocusIndex === 1) {
playPressSound();
@@ -124,6 +126,7 @@ const ScreenshotsView = memo(function ScreenshotsView() {
prev <= screenshots.length - 1 - cols ? prev + cols : prev,
);
} else if (e.key === "Enter") {
e.preventDefault();
if (screenshots[gridFocusIndex]) {
playPressSound();
setModalFocusIndex(2);
+1
View File
@@ -775,6 +775,7 @@ const SettingsView = memo(function SettingsView() {
item.onChange(newVal);
}
} else if (e.key === "Enter" && focusIndex !== null) {
e.preventDefault();
const item = settingsItems[focusIndex];
if (item.type === "button") {
item.onClick();
+1
View File
@@ -127,6 +127,7 @@ const SetupView: React.FC<SetupViewProps> = ({ onComplete }) => {
e.preventDefault();
setFocusIndex((prev) => (prev - 1 + count) % count);
} else if (e.key === "Enter") {
e.preventDefault();
if (currentStep === 0) {
if (focusIndex === 0) handleNext();
else if (focusIndex === 1) handleNext();
+1
View File
@@ -366,6 +366,7 @@ const SkinsView = memo(function SkinsView() {
setFocusIndex(next < SKINS_START_INDEX ? 0 : next);
}
} else if (e.key === "Enter" && focusIndex !== null) {
e.preventDefault();
if (focusIndex === 0) {
if (viewMode === "skin") handleImportClick();
else capeFileInputRef.current?.click();
+10 -2
View File
@@ -688,6 +688,7 @@ const WorkshopView = memo(function WorkshopView({
setFocusedIdx((p) => Math.max((p ?? 1) - (isPluginTab ? 1 : COLS), 0));
playPressSound();
} else if (e.key === "Enter" && focusedIdx !== null) {
e.preventDefault();
const pkg = filteredItems[focusedIdx];
if (pkg) openModal(pkg);
}
@@ -1402,6 +1403,7 @@ function PackageModal({
return focusOptions[(idx + 1) % focusOptions.length];
});
} else if (e.key === "Enter") {
e.preventDefault();
if (modalFocus === "close") onClose();
else if (modalFocus === "install") handleAction();
else if (modalFocus === "uninstall") setShowUninstall(true);
@@ -2171,8 +2173,10 @@ function InstallModal({
e.stopPropagation();
if (status === "installing") return;
if (status === "success") {
if (e.key === "Escape" || e.key === "Backspace" || e.key === "Enter")
if (e.key === "Escape" || e.key === "Backspace" || e.key === "Enter") {
e.preventDefault();
onClose();
}
return;
}
@@ -2187,6 +2191,7 @@ function InstallModal({
playPressSound();
setFocusedIdx((p) => Math.min(p + 1, editionOptions.length - 1));
} else if (e.key === "Enter") {
e.preventDefault();
if (editionOptions.length > 0) {
installTo(editionOptions[focusedIdx].instanceId);
}
@@ -2480,8 +2485,10 @@ function UninstallModal({
e.stopPropagation();
if (status === "removing") return;
if (status === "success") {
if (e.key === "Escape" || e.key === "Backspace" || e.key === "Enter")
if (e.key === "Escape" || e.key === "Backspace" || e.key === "Enter") {
e.preventDefault();
onClose();
}
return;
}
@@ -2496,6 +2503,7 @@ function UninstallModal({
playPressSound();
setFocusedIdx((p) => Math.min(p + 1, installedEntries.length - 1));
} else if (e.key === "Enter") {
e.preventDefault();
if (installedEntries.length > 0) {
uninstallFrom(installedEntries[focusedIdx].instanceId);
}