Skip to content

Bug: [@pierre/trees] row names with a space near the middle render with the space collapsed #744

@Gregory-Gerard

Description

@Gregory-Gerard

Prerequisites

Describe the issue

FileTreeView renders every row name through MiddleTruncate with minimumLength: 5 and split: "extension":

<MiddleTruncate minimumLength={5} split="extension">
{row.name}
</MiddleTruncate>

For names without a dot, splitExtension falls back to Math.ceil(length / 2):

export const splitExtension: CustomSplitFn = (contents) => {
if (contents.length < 4) {
return [contents, ''];
}
const lastDotIndex = contents.lastIndexOf('.');
const extensionIndex = lastDotIndex + 1;
const impliedExtensionLength = contents.length - extensionIndex;
const maxExtensionLength = 10;
const isTooLong = impliedExtensionLength > maxExtensionLength;
const splitIndex =
extensionIndex >= 1 && !isTooLong
? extensionIndex
: Math.ceil(contents.length / 2);
return [contents.slice(0, splitIndex), contents.slice(splitIndex)];
};

When that fallback splitIndex lands right after a space, the first segment ends with a trailing space. The two segments are then rendered side by side as inline elements, with the visible content carrying white-space: nowrap:

[data-truncate-content='visible'] {
white-space: nowrap;

Standard inline layout collapses the trailing whitespace at that boundary, so the name visually loses its space. The space is still present in the DOM (visible via the inspector), it just not "visible".

Example: "Hello world" (11 chars) = split at 6 = ["Hello ", "world"] = renders as Helloworld.

So the trigger is: extensionless name, length >= 5, with a space such that Math.ceil(length / 2) falls right after it.

Pretty niche, but I spent a few moments debugging this convinced the issue was on my side, haha 😅 Also, happy to try a PR if you think this is a good first issue.

Reproduction

On https://trees.software/, create a folder or file named Hello world. The row renders as Helloworld.

What browser(s) are you seeing the problem on?

No response

What version of @pierre/trees are you using?

1.0.0-beta.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtrees

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions