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(text): make overflow UTF-8 aware #963

Merged
merged 3 commits into from
Jul 20, 2020
Merged

Conversation

zbaylin
Copy link
Member

@zbaylin zbaylin commented Jul 20, 2020

This is a pretty simple fix, since Zed already gives us a function to do exactly what we were doing before but with UTF-8.

I will also add some tests for this, just to make sure it's robust!

@zbaylin zbaylin requested a review from bryphe July 20, 2020 17:55
@@ -10,7 10,7 @@ let removeLineBreaks = text => {
};

let rec handleOverflow = (~maxWidth, ~text, ~measure, ~character="…", ()) => {
let clippedText = String.length(text) - 1 |> Str.string_before(text);
let clippedText = Zed_utf8.rchop(text);
Copy link
Member

Choose a reason for hiding this comment

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

Nice find! I didn't know about this method - I'm glad there was already an efficient way to handle this.

width;

let abcSize = measure("ABC");
let overflown =
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding a test case 👍

Comment on lines 8 to 14
|> (
result =>
switch (result) {
| Ok(font) => font
| Error(e) => failwith(e)
}
);
Copy link
Member

Choose a reason for hiding this comment

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

Since this is a test case - would be fine to use Result.get_ok here (would simplify these lines)

@zbaylin zbaylin merged commit c05c047 into master Jul 20, 2020
@Et7f3 Et7f3 deleted the fix/text/overflow-utf8 branch May 6, 2021 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants