mirror of
https://github.com/LCE-Hub/LCE-Emerald-Launcher.git
synced 2026-09-24 17:11:00 +00:00
feat: preventDefault on Enter
This commit is contained in:
@@ -523,6 +523,7 @@ const SkinViewer = memo(function SkinViewer({
|
||||
} else if (e.key === "ArrowUp") {
|
||||
setFocusIndex((prev) => (prev > 0 ? prev - 1 : prev));
|
||||
} else if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
if (focusIndex === 0) {
|
||||
(
|
||||
containerRef.current?.querySelector("input") as HTMLElement
|
||||
|
||||
@@ -119,6 +119,7 @@ export default function ChooseInstanceModal({
|
||||
const max = 1 + (validInstances.length > 0 ? 1 : 0) + 1;
|
||||
setFocusIndex((prev) => (prev - 1 + max) % max);
|
||||
} else if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
if (focusIndex === 0 && validInstances.length > 0) {
|
||||
const currentIdx = validInstances.findIndex(
|
||||
(i: Edition) => i.instanceId === selectedInstance,
|
||||
|
||||
@@ -86,6 +86,7 @@ export default function CustomTUModal({
|
||||
playBackSound("close_click.wav");
|
||||
onClose();
|
||||
} else if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
if (focusIndex === 3) {
|
||||
playBackSound("close_click.wav");
|
||||
onClose();
|
||||
|
||||
@@ -58,6 +58,7 @@ export default function CustomizeModal({
|
||||
playBackSound("close_click.wav");
|
||||
onClose();
|
||||
} else if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
if (focusIndex === 4) {
|
||||
playBackSound("close_click.wav");
|
||||
onClose();
|
||||
|
||||
@@ -103,6 +103,7 @@ export default function SetUidModal({
|
||||
e.preventDefault();
|
||||
setFocusIndex((prev) => (prev - 1 + 5) % 5);
|
||||
} else if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
if (focusIndex === 0) {
|
||||
playPressSound();
|
||||
setMode("manual");
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user