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(completion): Fix hang when detail text is large #3533

Merged
merged 2 commits into from
May 12, 2021
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
1 change: 1 addition & 0 deletions CHANGES_CURRENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
- #3525 - CLI: Fix crash when opening non-existent file in running instance
- #3530 - UX: Fix click inside context menu from closing context menu (fixes #3510)
- #3532 - OSX: Fix crash when opening folder with Unicode characters (fixes #3519)
- #3533 - Completion: Fix hang when detail text is large

### Performance

Expand Down
6 changes: 6 additions & 0 deletions src/Core/Utility/StringEx.re
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ let characterCount = (~startByte, ~endByte, str) => {
loop(0, startByte);
};

let clamp = (~characters, str) => {
let characterCount = characterCount(~startByte=0, ~endByte=characters, str);

Zed_utf8.sub(str, 0, characterCount);
};

let characterToByte = (~index: EditorCoreTypes.CharacterIndex.t, str) => {
let idx = CharacterIndex.toInt(index);
let len = String.length(str);
Expand Down
3 changes: 2 additions & 1 deletion src/Feature/LanguageSupport/Completion.re
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,7 @@ module View = {
let maybeDetail =
switch (detail) {
| Some(detail) when isFocused && remainingWidth > 0 =>
let detail = StringEx.clamp(~characters=128, detail);
<View
style=Style.[
position(`Absolute),
Expand All @@ -1371,7 +1372,7 @@ module View = {
text=detail
/>
</View>
</View>
</View>;
| _ => React.empty
};

Expand Down