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

gpui: Add line_clamp to truncate text after a specified number of lines #23058

Merged
merged 3 commits into from
Jan 29, 2025

Conversation

huacnlee
Copy link
Contributor

@huacnlee huacnlee commented Jan 13, 2025

Release Notes:

  • N/A

Add this feature for some case we need keep 2 or 3 lines, but truncate. For example the blog post summary.

Break changes:

  • Renamed gpui::Truncate to gpui::TextOverflow to match CSS.

  • Update truncate style method to match Tailwind CSS behavior:

    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    image

Show case

image

CleanShot 2025-01-13 at 17 22 05

Describe changes

The second commit for make sure text layout to match with the line clamp. Before this change, they may wrap many lines in sometimes. And I also make line_clamp default to 1 if we used truncate to ensure no wrap.

TODO: There is still a tiny detail that is not easy to fix. This problem only occurs in the case of certain long words. I will think about how to improve it later. At present, this has some flaws but does not affect the use.

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Jan 13, 2025
@huacnlee huacnlee changed the title gpui: Add line_clamp to truncate text after a specified number of lines. gpui: Add line_clamp to truncate text after a specified number of lines Jan 13, 2025
@huacnlee huacnlee force-pushed the line-clamp branch 2 times, most recently from 9f37e94 to f5890c7 Compare January 13, 2025 09:45
@huacnlee huacnlee marked this pull request as draft January 13, 2025 10:00
pub enum Truncate {
/// Truncate the text without an ellipsis
#[default]
Truncate,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove Truncate to avoid ambiguity

self
}

/// Sets the truncate to prevent text from wrapping and truncate overflowing text with an ellipsis (…) if needed.
/// [Docs](https://tailwindcss.com/docs/text-overflow#truncate)
fn truncate(mut self) -> Self {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update truncate to default with overflow_hidden, whitespace_nowrap, text_ellipsis.

@huacnlee huacnlee marked this pull request as ready for review January 13, 2025 10:38
Copy link
Contributor

@SomeoneToIgnore SomeoneToIgnore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, let's merge/rebase on fresh main and get this merged after the next release.

@SomeoneToIgnore SomeoneToIgnore merged commit 706f7be into zed-industries:main Jan 29, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed The user has signed the Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants