From ae7d169b3fae2fc7fcbf72c9e3ae670b2cdfea71 Mon Sep 17 00:00:00 2001 From: bicarus <202771338+bicarus-dev@users.noreply.github.com> Date: Thu, 26 Nov 2026 02:17:52 -0800 Subject: [PATCH] cfg: trim surrounding whitespace in options tab (#935) ## Link to GitHub Issue or related Pull Request, if one exists n/a ## Description of change Remove leading and trailing whitespace for some commonly used options (EA server URL, pcbid, etc) to prevent users copy-pasting wrong text. ## Testing cfg only --- src/spice2x/cfg/option.h | 2 ++ src/spice2x/launcher/options.cpp | 4 ++++ src/spice2x/overlay/windows/config.cpp | 13 ++++++++++--- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/spice2x/cfg/option.h b/src/spice2x/cfg/option.h index 6890f329..2fa95c0a 100644 --- a/src/spice2x/cfg/option.h +++ b/src/spice2x/cfg/option.h @@ -48,6 +48,8 @@ struct OptionDefinition { std::string file_extension = ""; std::string quick_setting_category = ""; + + bool trim_whitespace = false; }; class Option { diff --git a/src/spice2x/launcher/options.cpp b/src/spice2x/launcher/options.cpp index 74e426f3..43c874ed 100644 --- a/src/spice2x/launcher/options.cpp +++ b/src/spice2x/launcher/options.cpp @@ -138,6 +138,7 @@ static const std::vector OPTION_DEFINITIONS = std::invoke([]() .setting_name = "example.com:8083", .category = "Network", .quick_setting_category = "Network", + .trim_whitespace = true, }; c[launcher::Options::PCBID] = { .title = "PCBID", @@ -148,6 +149,7 @@ static const std::vector OPTION_DEFINITIONS = std::invoke([]() .category = "Network", .sensitive = true, .quick_setting_category = "Network", + .trim_whitespace = true, }; c[launcher::Options::Player1Card] = { .title = "Player 1 Card", @@ -159,6 +161,7 @@ static const std::vector OPTION_DEFINITIONS = std::invoke([]() .sensitive = true, .picker = OptionPickerType::EACard, .quick_setting_category = "Network", + .trim_whitespace = true, }; c[launcher::Options::Player2Card] = { .title = "Player 2 Card", @@ -170,6 +173,7 @@ static const std::vector OPTION_DEFINITIONS = std::invoke([]() .sensitive = true, .picker = OptionPickerType::EACard, .quick_setting_category = "Network", + .trim_whitespace = true, }; c[launcher::Options::Player1PinMacro] = { .title = "Player 1 PIN Macro", diff --git a/src/spice2x/overlay/windows/config.cpp b/src/spice2x/overlay/windows/config.cpp index 1a4abb42..b95893a1 100644 --- a/src/spice2x/overlay/windows/config.cpp +++ b/src/spice2x/overlay/windows/config.cpp @@ -5282,9 +5282,16 @@ namespace overlay::windows { ImGui::InputTextWithHint("", hint, buffer, sizeof(buffer) - 1); // would like to use IsItemDeactivatedAfterEdit but can't handle the case when window is closed while editing if (ImGui::IsItemEdited()) { - this->options_dirty = true; - option.value = buffer; - ::Config::getInstance().updateBinding(games_list[games_selected], option); + // trim whitespace to prevent copy/paste errors + auto value = definition.trim_whitespace ? + strtrim(buffer) : std::string(buffer); + + if (option.value != value) { + this->options_dirty = true; + option.value = std::move(value); + ::Config::getInstance().updateBinding(games_list[games_selected], option); + } + } if (ImGui::IsItemHovered(ImGui::TOOLTIP_FLAGS)) { ImGui::HelpTooltip(definition.desc.c_str());