From 03f6231fff9ff526e6beb2c31fd666859839e15c Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Tue, 18 Aug 2020 14:58:20 -0700 Subject: [PATCH] Bugfix: layering would erase values when it couldn't find anything --- src/cascadia/TerminalApp/Profile.cpp | 53 +++++++++++++++++++--------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/src/cascadia/TerminalApp/Profile.cpp b/src/cascadia/TerminalApp/Profile.cpp index 67bcc4c6f25..75282436fe3 100644 --- a/src/cascadia/TerminalApp/Profile.cpp +++ b/src/cascadia/TerminalApp/Profile.cpp @@ -317,24 +317,39 @@ bool Profile::ShouldBeLayered(const Json::Value& json) const // void Profile::LayerJson(const Json::Value& json) { - std::optional guid; - std::optional color; + std::optional guid = std::nullopt; + std::optional color = std::nullopt; // Profile-specific Settings JsonUtils::GetValueForKey(json, NameKey, _Name); - JsonUtils::GetValueForKey(json, GuidKey, guid); - _Guid = guid.has_value() ? IReference{ guid.value() } : nullptr; + if (JsonUtils::GetValueForKey(json, GuidKey, guid)) + { + _Guid = guid.has_value() ? IReference{ guid.value() } : nullptr; + guid.reset(); + } JsonUtils::GetValueForKey(json, HiddenKey, _Hidden); // Core Settings - JsonUtils::GetValueForKey(json, ForegroundKey, color); - _Foreground = color.has_value() ? IReference{ color.value() } : nullptr; - JsonUtils::GetValueForKey(json, BackgroundKey, color); - _Background = color.has_value() ? IReference{ color.value() } : nullptr; - JsonUtils::GetValueForKey(json, SelectionBackgroundKey, color); - _SelectionBackground = color.has_value() ? IReference{ color.value() } : nullptr; - JsonUtils::GetValueForKey(json, CursorColorKey, color); - _CursorColor = color.has_value() ? IReference{ color.value() } : nullptr; + if (JsonUtils::GetValueForKey(json, ForegroundKey, color)) + { + _Foreground = color.has_value() ? IReference{ color.value() } : nullptr; + color.reset(); + } + if (JsonUtils::GetValueForKey(json, BackgroundKey, color)) + { + _Background = color.has_value() ? IReference{ color.value() } : nullptr; + color.reset(); + } + if (JsonUtils::GetValueForKey(json, SelectionBackgroundKey, color)) + { + _SelectionBackground = color.has_value() ? IReference{ color.value() } : nullptr; + color.reset(); + } + if (JsonUtils::GetValueForKey(json, CursorColorKey, color)) + { + _CursorColor = color.has_value() ? IReference{ color.value() } : nullptr; + color.reset(); + } JsonUtils::GetValueForKey(json, ColorSchemeKey, _ColorSchemeName); // TODO:MSFT:20642297 - Use a sentinel value (-1) for "Infinite scrollback" @@ -347,8 +362,11 @@ void Profile::LayerJson(const Json::Value& json) // Control Settings JsonUtils::GetValueForKey(json, FontWeightKey, _FontWeight); - JsonUtils::GetValueForKey(json, ConnectionTypeKey, guid); - _ConnectionType = guid.has_value() ? IReference{ guid.value() } : nullptr; + if (JsonUtils::GetValueForKey(json, ConnectionTypeKey, guid)) + { + _ConnectionType = guid.has_value() ? IReference{ guid.value() } : nullptr; + guid.reset(); + } JsonUtils::GetValueForKey(json, CommandlineKey, _Commandline); JsonUtils::GetValueForKey(json, FontFaceKey, _FontFace); JsonUtils::GetValueForKey(json, FontSizeKey, _FontSize); @@ -371,8 +389,11 @@ void Profile::LayerJson(const Json::Value& json) JsonUtils::GetValueForKey(json, RetroTerminalEffectKey, _RetroTerminalEffect); JsonUtils::GetValueForKey(json, AntialiasingModeKey, _AntialiasingMode); - JsonUtils::GetValueForKey(json, TabColorKey, color); - _TabColor = color.has_value() ? IReference{ color.value() } : nullptr; + if (JsonUtils::GetValueForKey(json, TabColorKey, color)) + { + _TabColor = color.has_value() ? IReference{ color.value() } : nullptr; + color.reset(); + } } // Method Description: