Skip to content

Columns with expandUntil are not as tight as they could be with WideString #35

@Xitian9

Description

@Xitian9

The existing code is built around the assumption that you can always drop an exact length from the left or right of a Cell. This is true of String and Text, but not true of WideString and WideText. To get around this, WideString and WideText are padded with spaces if dropping characters goes too far.

For example: dropLeft 1 (WideString "㐁㐂") = WideString " 㐂", and dropRight 1 (WideString "㐁㐂") = WideString "㐁 ".

This is perfectly fine, but when using the ExpandUntil strategy for columns, it sometimes produces columns that are (slightly) too wide. If you try to put WideString "㐁㐂" into a column with policy ExpandUntil 3, it will drop one (width 2) character from the string, pad it with a space, and put it into the column. If all other entries in the column are of length 2 or shorter, this extra space of padding is unnecessary, and the entire column can be shrunk to width 2.

In the case of WideString and WideText this is not too much of a problem, as it at most results in one extra space. However, there could be other instances of Cell (such as the proposed ElidableList in #34) where the difference is more noticable.

I think the solution is that we need a new function in Cell a which gives you the list of all natural truncations. We can the determine the best width for ExpandUntil by, for each element of the column, finding the largest natural truncation which is smaller than the limit, and then taking the maximum of all those. This is complicated by needing both a list of left truncations and a list of right truncations, depending on whether we're using left or right positioning. And for centre positioning we'd need to combine the two.

Or perhaps there's another way of achieving the same effect. Let me know if you have any thoughts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions