When soft wrap is on, don't position hidden input beyond width of horizontal scroller.

This commit is contained in:
Nathan Sobo
2012-03-13 12:14:08 -06:00
parent f02244412f
commit a96e09f6d1
2 changed files with 13 additions and 2 deletions

View File

@@ -174,6 +174,15 @@ describe "Editor", ->
it "moves the hidden input element to the position of the cursor to prevent scrolling misbehavior", ->
expect(editor.hiddenInput.position()).toEqual(top: 2 * editor.lineHeight, left: 2 * editor.charWidth)
describe "if soft-wrap is enabled", ->
beforeEach ->
setEditorWidthInChars(editor, 20)
editor.setSoftWrap(true)
it "doesn't move the hidden input beyond the right side of the horizontal scroller to prevent chrome from auto-scrolling", ->
editor.setCursorScreenPosition([4, 20])
expect(editor.hiddenInput.position()).toEqual(top: 4 * editor.lineHeight, left: editor.horizontalScroller.width() - editor.charWidth)
describe "when the arrow keys are pressed", ->
it "moves the cursor by a single row/column", ->
editor.trigger keydownEvent('right')
@@ -569,7 +578,6 @@ describe "Editor", ->
expect(editor.buffer.lineForRow(5)).toEqual(" }")
expect(editor.getCursorBufferPosition().column).toBe 5
describe "selection", ->
selection = null

View File

@@ -120,7 +120,10 @@ class Editor extends View
@insertText(e.originalEvent.data)
@on 'cursor:position-changed', =>
@hiddenInput.css(@pixelPositionForScreenPosition(@cursor.getScreenPosition()))
position = @pixelPositionForScreenPosition(@cursor.getScreenPosition())
if @softWrap
position.left = Math.min(position.left, @horizontalScroller.width() - @charWidth)
@hiddenInput.css(position)
@one 'attach', =>
@calculateDimensions()