Skip to content

Commit

Permalink
Completion: Fix hang on large detail text
Browse files Browse the repository at this point in the history
  • Loading branch information
bryphe committed May 12, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 9d265fd commit cd58a40
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Core/Utility/StringEx.re
Original file line number Diff line number Diff line change
@@ -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);
3 changes: 2 additions & 1 deletion src/Feature/LanguageSupport/Completion.re
Original file line number Diff line number Diff line change
@@ -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),
@@ -1371,7 +1372,7 @@ module View = {
text=detail
/>
</View>
</View>
</View>;
| _ => React.empty
};

0 comments on commit cd58a40

Please sign in to comment.