Skip to content

Commit 700b64b

Browse files
committed
simpler and more efficient suggestions autoplace
1 parent af727f1 commit 700b64b

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

src/components/SuggestionsDropdown.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ export const SuggestionsDropdown: React.FunctionComponent<SuggestionsDropdownPro
5151
suggestionsAutoplace &&
5252
top +
5353
textAreaRef.current.getBoundingClientRect().top +
54-
textAreaRef.current.ownerDocument.defaultView.pageYOffset +
55-
caret.lineHeight * 1.5 * suggestions.length >
56-
vh
54+
textAreaRef.current.ownerDocument.defaultView.pageYOffset >
55+
vh / 2
5756
)
5857
style.bottom = textAreaRef.current.offsetHeight - caret.top;
5958
else style.top = top;
@@ -62,14 +61,8 @@ export const SuggestionsDropdown: React.FunctionComponent<SuggestionsDropdownPro
6261
suggestionsAutoplace &&
6362
left +
6463
textAreaRef.current.getBoundingClientRect().left +
65-
textAreaRef.current.ownerDocument.defaultView.pageXOffset +
66-
caret.lineHeight *
67-
0.6666 *
68-
Math.max.apply(
69-
Math,
70-
suggestions.map(x => x.preview.toString().length)
71-
) >
72-
vw
64+
textAreaRef.current.ownerDocument.defaultView.pageXOffset >
65+
vw / 2
7366
)
7467
style.right = textAreaRef.current.offsetWidth - caret.left;
7568
else style.left = left;

0 commit comments

Comments
 (0)