Always keep hidden input position in visible area

Previously the input could be offscreen depend on the scroll
position of the editor and this would cause a scroll event to
occur when the input gained focused causing the editor rendering
to go out of sync.
This commit is contained in:
Kevin Sawicki
2013-09-25 11:53:14 -07:00
parent 9006ab95fc
commit 84efe44a5a

View File

@@ -630,6 +630,7 @@ class Editor extends View
handleEvents: ->
@on 'focus', =>
@updateHiddenInputOffset()
@hiddenInput.focus()
false
@@ -693,10 +694,15 @@ class Editor extends View
else
@gutter.addClass('drop-shadow')
updateHiddenInputOffset: ->
cursorView = @getCursorView()
if cursorView?.is(':visible')
offset = cursorView.offset()
offset.top = Math.min(@height(), offset.top)
@hiddenInput.offset(offset)
handleInputEvents: ->
@on 'cursor:moved', =>
cursorView = @getCursorView()
@hiddenInput.offset(cursorView.offset()) if cursorView.is(':visible')
@on 'cursor:moved', => @updateHiddenInputOffset()
selectedText = null
@hiddenInput.on 'compositionstart', =>