From a96e09f6d1f5dd484ae54bccc06ff817025e3365 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 13 Mar 2012 12:14:08 -0600 Subject: [PATCH] When soft wrap is on, don't position hidden input beyond width of horizontal scroller. --- spec/atom/editor-spec.coffee | 10 +++++++++- src/atom/editor.coffee | 5 ++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/spec/atom/editor-spec.coffee b/spec/atom/editor-spec.coffee index 70135736c..3180d025d 100644 --- a/spec/atom/editor-spec.coffee +++ b/spec/atom/editor-spec.coffee @@ -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 diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index b11f188e2..b6260fc4f 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -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()