Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading