Skip to content

Commit

Permalink
fix(TextComponent): add white-space pre formatting for inline text (C…
Browse files Browse the repository at this point in the history
…CBlueX#4985)

* fix(TextComponent): add white-space pre formatting for inline text

* feat(TextComponent): add preFormattingMonospace

* fix(multiplayer): disable preFormattingMonospace for TextComponent
  • Loading branch information
sokripon authored and commandblock2 committed Dec 31, 2024
1 parent 6697138 commit dea9149
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src-theme/src/routes/menu/common/TextComponent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export let textComponent: TTextComponent | string;
export let allowPreformatting = false;
export let preFormattingMonospace = true;
export let inheritedColor = "#ffffff";
export let inheritedStrikethrough = false;
export let inheritedItalic = false;
Expand Down Expand Up @@ -107,7 +108,7 @@

<span class="text-component">
{#if typeof textComponent === "string"}
<svelte:self {fontSize} {allowPreformatting} textComponent={convertLegacyCodes(textComponent)}/>
<svelte:self {fontSize} {allowPreformatting} {preFormattingMonospace} textComponent={convertLegacyCodes(textComponent)}/>
{:else if textComponent}
{#if textComponent.text}
{#if !textComponent.text.includes("§")}
Expand All @@ -116,9 +117,10 @@
class:underlined={textComponent.underlined !== undefined ? textComponent.underlined : inheritedUnderlined}
class:strikethrough={textComponent.strikethrough !== undefined ? textComponent.strikethrough : inheritedStrikethrough}
class:allow-preformatting={allowPreformatting}
class:monospace={preFormattingMonospace && allowPreformatting}
style="color: {textComponent.color !== undefined ? translateColor(textComponent.color) : translateColor(inheritedColor)}; font-size: {fontSize}px;">{textComponent.text}</span>
{:else}
<svelte:self {allowPreformatting} {fontSize}
<svelte:self {allowPreformatting} {preFormattingMonospace} {fontSize}
inheritedColor={textComponent.color !== undefined ? textComponent.color : inheritedColor}
inheritedBold={textComponent.bold !== undefined ? textComponent.bold : inheritedBold}
inheritedItalic={textComponent.italic !== undefined ? textComponent.italic : inheritedItalic}
Expand All @@ -129,7 +131,7 @@
{/if}
{#if textComponent.extra}
{#each textComponent.extra as e}
<svelte:self {allowPreformatting} {fontSize}
<svelte:self {allowPreformatting} {preFormattingMonospace} {fontSize}
inheritedColor={textComponent.color !== undefined ? textComponent.color : inheritedColor}
inheritedBold={textComponent.bold !== undefined ? textComponent.bold : inheritedBold}
inheritedItalic={textComponent.italic !== undefined ? textComponent.italic : inheritedItalic}
Expand All @@ -150,10 +152,13 @@
display: inline;
&.allow-preformatting {
font-family: monospace;
white-space: pre;
}
&.monospace {
font-family: monospace;
}
&.bold {
font-weight: 500;
}
Expand Down
2 changes: 1 addition & 1 deletion src-theme/src/routes/menu/multiplayer/Multiplayer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
:`data:image/png;base64,${server.icon}`}
title={server.name}
on:dblclick={() => connectToServer(server.address)}>
<TextComponent slot="subtitle" fontSize={18}
<TextComponent allowPreformatting={true} preFormattingMonospace={false} slot="subtitle" fontSize={18}
textComponent={server.ping <= 0 ? "§CCan't connect to server" : server.label}/>

<svelte:fragment slot="tag">
Expand Down

0 comments on commit dea9149

Please sign in to comment.