From dda61e9c1ac7c9ae69e0c1dcf2a902ba04bc179f Mon Sep 17 00:00:00 2001 From: Miguel <81558772+Miguel-hrvs@users.noreply.github.com> Date: Sat, 3 Aug 2024 17:14:58 +0200 Subject: [PATCH] fix f1 hotkey conflict --- src/studio/editors/code.c | 10 ++++++++-- src/studio/studio.c | 26 +++++++++++++++++++++++++- src/studio/system.h | 2 ++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/studio/editors/code.c b/src/studio/editors/code.c index 97238f1c6..79eaceb57 100644 --- a/src/studio/editors/code.c +++ b/src/studio/editors/code.c @@ -2957,9 +2957,15 @@ static void processKeyboard(Code* code) } bool usedKeybinding = true; - + + if(hasJustSwitchedToCodeMode(code->studio)) + { + setJustSwitchedToCodeMode(code->studio, false); + return; // Skip processing other inputs for this frame + } + // handle bookmarks - if(keyWasPressed(code->studio, tic_key_f7)) + if(keyWasPressed(code->studio, tic_key_f1)) { if(ctrl && shift) { diff --git a/src/studio/studio.c b/src/studio/studio.c index 7bea1972a..6dbe8a420 100644 --- a/src/studio/studio.c +++ b/src/studio/studio.c @@ -1771,6 +1771,23 @@ static bool enterWasPressedOnce(Studio* studio) keyWasPressedOnce(studio, tic_key_numpadenter); } +#if defined(BUILD_EDITORS) +// These three are to fix the f1 hotkey conflict + +// Add a static variable in studio.c to track the mode switch +static bool justSwitchedToCodeMode = false; + +void setJustSwitchedToCodeMode(Studio* studio, bool value) +{ + justSwitchedToCodeMode = value; +} + +bool hasJustSwitchedToCodeMode(Studio* studio) +{ + return justSwitchedToCodeMode; +} +#endif + #if defined(BUILD_EDITORS) static bool showGameMenu(Studio* studio) @@ -1890,7 +1907,14 @@ static void processShortcuts(Studio* studio) if(!showGameMenu(studio) || studio->mode != TIC_RUN_MODE) { - if(keyWasPressedOnce(studio, tic_key_f1)) setStudioMode(studio, TIC_CODE_MODE); + if(keyWasPressedOnce(studio, tic_key_f1)) + { + if(studio->mode != TIC_CODE_MODE) + { + setStudioMode(studio, TIC_CODE_MODE); + setJustSwitchedToCodeMode(studio, true); + } + } else if(keyWasPressedOnce(studio, tic_key_f2)) setStudioMode(studio, TIC_SPRITE_MODE); else if(keyWasPressedOnce(studio, tic_key_f3)) setStudioMode(studio, TIC_MAP_MODE); else if(keyWasPressedOnce(studio, tic_key_f4)) setStudioMode(studio, TIC_SFX_MODE); diff --git a/src/studio/system.h b/src/studio/system.h index f7e970a9b..a1ba3a81e 100644 --- a/src/studio/system.h +++ b/src/studio/system.h @@ -156,6 +156,8 @@ typedef struct typedef struct Studio Studio; +void setJustSwitchedToCodeMode(Studio* studio, bool value); +bool hasJustSwitchedToCodeMode(Studio* studio); const tic_mem* studio_mem(Studio* studio); void studio_tick(Studio* studio, tic80_input input); void studio_sound(Studio* studio);