refactor(config): cleanup handling for fontSize, tapeMargin and maxLineWidth (@fehmer) (#6775)

merge this after #6751 and the command builder pr

- remove configOverride
- add handling to config migration
This commit is contained in:
Christian Fehmer 2025-07-28 15:42:18 +02:00 committed by GitHub
parent be1774e219
commit 3ddb3c68c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 47 additions and 35 deletions

View file

@ -1042,9 +1042,6 @@ describe("Config", () => {
it("setFontSize", () => {
expect(Config.setFontSize(1)).toBe(true);
//gets converted
expect(Config.setFontSize(-1)).toBe(true);
expect(Config.setFontSize(0)).toBe(false);
expect(Config.setFontSize("5" as any)).toBe(false);
expect(Config.setFontSize("invalid" as any)).toBe(false);
@ -1053,11 +1050,6 @@ describe("Config", () => {
expect(Config.setMaxLineWidth(0)).toBe(true);
expect(Config.setMaxLineWidth(50)).toBe(true);
expect(Config.setMaxLineWidth(50.5)).toBe(true);
//gets converted
expect(Config.setMaxLineWidth(10)).toBe(true);
expect(Config.setMaxLineWidth(10_000)).toBe(true);
expect(Config.setMaxLineWidth("invalid" as any)).toBe(false);
});
it("setCustomBackground", () => {
expect(Config.setCustomBackground("http://example.com/test.png")).toBe(

View file

@ -209,6 +209,35 @@ describe("config.ts", () => {
given: { fontSize: 15 },
expected: { fontSize: 15 },
},
{
given: { fontSize: -0.5 },
expected: { fontSize: 1 },
},
{
given: { tapeMargin: 9.5 },
expected: { tapeMargin: 10 },
},
{
given: { tapeMargin: 25 },
expected: { tapeMargin: 25 },
},
{
given: { tapeMargin: 90.5 },
expected: { tapeMargin: 90 },
},
{
given: { maxLineWidth: 0 },
expected: { maxLineWidth: 0 },
},
{
given: { maxLineWidth: 19 },
expected: { maxLineWidth: 20 },
},
{
given: { maxLineWidth: 1001 },
expected: { maxLineWidth: 1000 },
},
])(`$given`, ({ given, expected }) => {
const description = `given: ${JSON.stringify(
given

View file

@ -500,16 +500,6 @@ export const configMetadata: ConfigMetadataObject = {
icon: "fa-tape",
displayString: "tape margin",
changeRequiresRestart: false,
overrideValue: ({ value }) => {
//TODO move to migration after settings validation
if (value < 10) {
value = 10;
}
if (value > 90) {
value = 90;
}
return value;
},
},
smoothLineScroll: {
icon: "fa-align-left",
@ -548,29 +538,12 @@ export const configMetadata: ConfigMetadataObject = {
changeRequiresRestart: false,
triggerResize: true,
displayString: "max line width",
overrideValue: ({ value }) => {
//TODO move to migration after settings validation
if (value < 20 && value !== 0) {
value = 20;
}
if (value > 1000) {
value = 1000;
}
return value;
},
},
fontSize: {
icon: "fa-font",
changeRequiresRestart: false,
triggerResize: true,
displayString: "font size",
overrideValue: ({ value }) => {
//TODO move to migration after settings validation
if (value < 0) {
value = 1;
}
return value;
},
},
fontFamily: {
icon: "fa-font",

View file

@ -154,6 +154,8 @@ export function replaceLegacyValues(
}
configObj.fontSize = newValue;
} else if (configObj.fontSize !== undefined && configObj.fontSize < 0) {
configObj.fontSize = 1;
}
if (
@ -198,5 +200,21 @@ export function replaceLegacyValues(
}
}
if (configObj.tapeMargin !== undefined) {
if (configObj.tapeMargin < 10) {
configObj.tapeMargin = 10;
} else if (configObj.tapeMargin > 90) {
configObj.tapeMargin = 90;
}
}
if (configObj.maxLineWidth !== undefined) {
if (configObj.maxLineWidth < 20 && configObj.maxLineWidth !== 0) {
configObj.maxLineWidth = 20;
} else if (configObj.maxLineWidth > 1000) {
configObj.maxLineWidth = 1000;
}
}
return configObj;
}