Position autocomplete menu above cursor if there isn't room below

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-04-20 17:18:07 -06:00
parent 11c465b7fd
commit f652b4e357
6 changed files with 42 additions and 20 deletions

View File

@@ -100,12 +100,12 @@ class Autocomplete extends View
@originalSelectionBufferRange = @editor.getSelection().getBufferRange()
@allMatches = @findMatchesForCurrentSelection()
cursorScreenPosition = @editor.getCursorScreenPosition()
{left, top} = @editor.pixelPositionForScreenPosition(cursorScreenPosition)
@css {left: left, top: top + @editor.lineHeight}
originalCursorPosition = @editor.getCursorScreenPosition()
@filterMatches()
@editor.lines.append(this)
@setPosition(originalCursorPosition)
@miniEditor.focus()
detach: ->
@@ -114,6 +114,15 @@ class Autocomplete extends View
super
@miniEditor.buffer.setText('')
setPosition: (originalCursorPosition) ->
{ left, top } = @editor.pixelPositionForScreenPosition(originalCursorPosition)
potentialTop = top + @editor.lineHeight
potentialBottom = potentialTop + @outerHeight()
if potentialBottom > @editor.scroller.scrollBottom()
@css(left: left, bottom: @editor.lines.height() - top, top: 'inherit')
else
@css(left: left, top: potentialTop, bottom: 'inherit')
selectPreviousMatch: ->
previousIndex = @currentMatchIndex - 1
previousIndex = @filteredMatches.length - 1 if previousIndex < 0