mirror of
https://github.com/microsoft/terminal.git
synced 2026-02-04 01:04:33 +00:00
Fix initial position parsing from -pos tag (#19409)
## Summary of the Pull Request Fixes #4247. Improves consistency in -pos tag parsing by supporting single-value input for both axes. ## References and Relevant Issues #4247 ## Detailed Description of the Pull Request / Additional comments The change aligns -pos behavior with padding-style logic. Existing comma-separated behavior remains unchanged. - A single value like "number" now sets both x and y positions to that value — similar to how padding behaves. - A value like "number," (with a trailing comma) continues to set only x, leaving y unchanged. ## Validation Steps Performed - Ran all unit and integration tests - Added unit test to verify single-value and comma-separated inputs ## PR Checklist - [x] Closes #4247 - [x] Tests added/passed - [x] Documentation updated https://github.com/MicrosoftDocs/terminal/pull/890 --------- Co-authored-by: Carlos Zamora <cazamor@microsoft.com>
This commit is contained in:
@@ -27,6 +27,7 @@ Two new properties should be added in the json settings file:
|
|||||||
|
|
||||||
2. Both X value and Y values are optional. If any one of them is missing, or the value is invalid, system default value will be used. Examples:
|
2. Both X value and Y values are optional. If any one of them is missing, or the value is invalid, system default value will be used. Examples:
|
||||||
|
|
||||||
|
"1000" equals (1000, 1000)
|
||||||
", 1000" equals (default, 1000)
|
", 1000" equals (default, 1000)
|
||||||
"1000, " equals (1000, default)
|
"1000, " equals (1000, default)
|
||||||
"," equals (default, default)
|
"," equals (default, default)
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ Abstract:
|
|||||||
// - Helper for converting a pair of comma separated, potentially absent integer values
|
// - Helper for converting a pair of comma separated, potentially absent integer values
|
||||||
// into the corresponding left and right values. The leftValue and rightValue functions
|
// into the corresponding left and right values. The leftValue and rightValue functions
|
||||||
// will be called back with the associated parsed integer value, assuming it's present.
|
// will be called back with the associated parsed integer value, assuming it's present.
|
||||||
// (100, 100): leftValue and rightValue functions both called back with 100.
|
// (100, 100), (100): leftValue and rightValue functions both called back with 100.
|
||||||
// (100, ), (100, abc): leftValue function called back with 100
|
// (100, ), (100, abc): leftValue function called back with 100
|
||||||
// (, 100), (abc, 100): rightValue function called back with 100
|
// (, 100), (abc, 100): rightValue function called back with 100
|
||||||
// (,): no function called back
|
// (,), (abc): no function called back
|
||||||
// (100, 100, 100): we only read the first two values, this is equivalent to (100, 100)
|
// (100, 100, 100): we only read the first two values, this is equivalent to (100, 100)
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// - string: The string to parse
|
// - string: The string to parse
|
||||||
@@ -45,6 +45,10 @@ _TIL_INLINEPREFIX void ParseCommaSeparatedPair(const std::string& string,
|
|||||||
if (index == 0)
|
if (index == 0)
|
||||||
{
|
{
|
||||||
leftValue(value);
|
leftValue(value);
|
||||||
|
if (string.find(',') == std::string::npos)
|
||||||
|
{
|
||||||
|
rightValue(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index == 1)
|
if (index == 1)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <pcg_random.hpp>
|
#include <pcg_random.hpp>
|
||||||
|
|
||||||
#include "../TerminalSettingsModel/CascadiaSettings.h"
|
#include "../TerminalSettingsModel/CascadiaSettings.h"
|
||||||
|
#include "../TerminalSettingsModel/ModelSerializationHelpers.h"
|
||||||
#include "TestUtils.h"
|
#include "TestUtils.h"
|
||||||
|
|
||||||
using namespace Microsoft::Console;
|
using namespace Microsoft::Console;
|
||||||
@@ -52,6 +53,7 @@ namespace SettingsModelUnitTests
|
|||||||
TEST_METHOD(MakeSettingsForDefaultProfileThatDoesntExist);
|
TEST_METHOD(MakeSettingsForDefaultProfileThatDoesntExist);
|
||||||
TEST_METHOD(TestLayerProfileOnColorScheme);
|
TEST_METHOD(TestLayerProfileOnColorScheme);
|
||||||
TEST_METHOD(TestCommandlineToTitlePromotion);
|
TEST_METHOD(TestCommandlineToTitlePromotion);
|
||||||
|
TEST_METHOD(TestInitialPositionParsing);
|
||||||
};
|
};
|
||||||
|
|
||||||
// CascadiaSettings::_normalizeCommandLine abuses some aspects from CommandLineToArgvW
|
// CascadiaSettings::_normalizeCommandLine abuses some aspects from CommandLineToArgvW
|
||||||
@@ -891,4 +893,49 @@ namespace SettingsModelUnitTests
|
|||||||
VERIFY_ARE_EQUAL(L"", settingsStruct.DefaultSettings()->StartingTitle());
|
VERIFY_ARE_EQUAL(L"", settingsStruct.DefaultSettings()->StartingTitle());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void TerminalSettingsTests::TestInitialPositionParsing()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
const auto pos = LaunchPositionFromString("50");
|
||||||
|
VERIFY_IS_TRUE(pos.X.Value());
|
||||||
|
VERIFY_IS_TRUE(pos.Y.Value());
|
||||||
|
VERIFY_ARE_EQUAL(50, static_cast<int32_t>(pos.X.Value()));
|
||||||
|
VERIFY_ARE_EQUAL(50, static_cast<int32_t>(pos.Y.Value()));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const auto pos = LaunchPositionFromString("100,");
|
||||||
|
VERIFY_IS_TRUE(pos.X.Value());
|
||||||
|
VERIFY_ARE_EQUAL(100, static_cast<int32_t>(pos.X.Value()));
|
||||||
|
VERIFY_IS_TRUE(pos.Y == nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const auto pos = LaunchPositionFromString(",100");
|
||||||
|
VERIFY_IS_TRUE(pos.X == nullptr);
|
||||||
|
VERIFY_IS_TRUE(pos.Y.Value());
|
||||||
|
VERIFY_ARE_EQUAL(100, static_cast<int32_t>(pos.Y.Value()));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const auto pos = LaunchPositionFromString("50,50");
|
||||||
|
VERIFY_IS_TRUE(pos.X.Value());
|
||||||
|
VERIFY_ARE_EQUAL(50, static_cast<int32_t>(pos.X.Value()));
|
||||||
|
VERIFY_IS_TRUE(pos.Y.Value());
|
||||||
|
VERIFY_ARE_EQUAL(50, static_cast<int32_t>(pos.Y.Value()));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const auto pos = LaunchPositionFromString("abc,100");
|
||||||
|
VERIFY_IS_TRUE(pos.X == nullptr);
|
||||||
|
VERIFY_IS_TRUE(pos.Y.Value());
|
||||||
|
VERIFY_ARE_EQUAL(100, static_cast<int32_t>(pos.Y.Value()));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const auto pos = LaunchPositionFromString("abc");
|
||||||
|
VERIFY_IS_TRUE(pos.X == nullptr);
|
||||||
|
VERIFY_IS_TRUE(pos.Y == nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user