--- a/EditTextViewCompletionSupport.st Fri Oct 21 00:20:54 2016 +0200
+++ b/EditTextViewCompletionSupport.st Sun Oct 23 11:40:11 2016 +0200
@@ -296,13 +296,24 @@
openCompletionView: list
"Makes sure the completion view is opened and with given `list`."
- | cursorPos movePos topView limit |
+ | textCursorPosInTextView textCursorPosOnScreen movePos topView
+ screenBounds screenBoundsCorner
+ helpViewsExtent helpViewsWidth helpViewsHeight|
- "/ move the window
- cursorPos := editView device translatePoint:(editView xOfCursor @ editView yOfCursor) fromView:editView toView:nil.
- cursorPos := cursorPos - (editView viewOrigin x @ 0).
+ "/ move the window away from the text cursor (to not cover what user types in)
+ "/ get the screen-relative position of the text cursor
+ textCursorPosInTextView := editView xOfCursor @ editView yOfCursor.
+
+ "/ care for the scroll-offset (xOfCursor/yOFCursor gives me
+ textCursorPosInTextView := textCursorPosInTextView - (editView viewOrigin x @ 0).
+
+ textCursorPosOnScreen := editView device
+ translatePoint:textCursorPosInTextView
+ fromView:editView toView:nil.
+
"/ currently, we have to stay away a bit, to avoid getting the focus
- movePos := cursorPos + (60 @ (editView font height)).
+ "/ this will be somewhat to the down-right of the textCursor
+ movePos := textCursorPosOnScreen + (60 @ (editView font height)).
completionView isNil ifTrue:[
completionView := CodeCompletionHelpMenuView new.
@@ -318,19 +329,28 @@
completionView list:list.
topView := completionView topView.
].
+
topView ~~ completionView ifTrue:[
topView resizeToFit.
-"/ movePos := editView device
-"/ translatePoint:((editView right - topView width) @ (editView top))
-"/ fromView:editView toView:nil.
+
"/ make sure, the window is visible
- limit := topView device monitorBoundsAt:topView origin.
- movePos x + topView extent x > limit corner x ifTrue:[
- movePos := (cursorPos x - 60 - (topView extent x)) @ movePos y.
+ screenBounds := topView device monitorBoundsAt:topView origin.
+ screenBoundsCorner := screenBounds corner.
+
+ helpViewsExtent := topView extent.
+ helpViewsWidth := helpViewsExtent x.
+ helpViewsHeight := helpViewsExtent y.
+
+ "/ if it does not lie completely inside the screen, move it
+ (movePos x + helpViewsWidth) > screenBoundsCorner x ifTrue:[
+ movePos := (textCursorPosOnScreen x - 60 - helpViewsWidth) @ movePos y.
].
- movePos y + topView extent y > limit corner y ifTrue:[
- movePos := movePos x @ (cursorPos y - (topView extent y)).
+ (movePos y + helpViewsHeight) > screenBoundsCorner y ifTrue:[
+ movePos := movePos x @ (textCursorPosOnScreen y - helpViewsHeight).
].
+ movePos y < 0 ifTrue:[
+ movePos := movePos x @ 0
+ ].
topView origin:movePos.
].