Skip to content

Commit 58be534

Browse files
committed
Fix #15: Improve Auto complete drop down position when cursor on the end of the visible view
1 parent c077612 commit 58be534

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

codeview/src/main/java/com/amrdeveloper/codeview/CodeView.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -648,9 +648,6 @@ public void showDropDown() {
648648
final int[] screenPoint = new int[2];
649649
getLocationOnScreen(screenPoint);
650650

651-
final Rect displayFrame = new Rect();
652-
getWindowVisibleDisplayFrame(displayFrame);
653-
654651
final Layout layout = getLayout();
655652
final int position = getSelectionStart();
656653
final int line = layout.getLineForOffset(position);
@@ -667,8 +664,17 @@ public void showDropDown() {
667664
dropDownHeight = modifiedDropDownHeight;
668665
}
669666

667+
final Rect displayFrame = new Rect();
668+
getWindowVisibleDisplayFrame(displayFrame);
669+
int displayFrameHeight = displayFrame.height();
670+
671+
int verticalOffset = lineButton + dropDownHeight;
672+
if (verticalOffset > displayFrameHeight) {
673+
verticalOffset = displayFrameHeight - autoCompleteItemHeightInDp;
674+
}
675+
670676
setDropDownHeight(dropDownHeight);
671-
setDropDownVerticalOffset(lineButton + dropDownHeight);
677+
setDropDownVerticalOffset(verticalOffset);
672678
setDropDownHorizontalOffset((int) layout.getPrimaryHorizontal(position));
673679

674680
super.showDropDown();

0 commit comments

Comments
 (0)