From 29c697faaa70de1ca7d86e8350817ab12c61a5e9 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Wed, 7 Mar 2012 11:20:47 -0800 Subject: [PATCH] Disable auto-scroll and make overflow-x hidden when soft-wrap is enabled --- spec/atom/editor-spec.coffee | 54 ++++++++++++++++++++++++++++++++++++ src/atom/cursor.coffee | 4 ++- src/atom/editor.coffee | 3 ++ static/editor.css | 6 +++- 4 files changed, 65 insertions(+), 2 deletions(-) diff --git a/spec/atom/editor-spec.coffee b/spec/atom/editor-spec.coffee index 69c2567ce..e7416e1b3 100644 --- a/spec/atom/editor-spec.coffee +++ b/spec/atom/editor-spec.coffee @@ -353,6 +353,60 @@ describe "Editor", -> editor.setCursorScreenPosition([2, 3]) expect(editor.lines.scrollLeft()).toBe(0) + describe "when soft-wrap is on", -> + beforeEach -> + editor.setSoftWrap(true) + + it "does not scroll the buffer", -> + editor.width(charWidth * 30) + + # moving right + editor.setCursorScreenPosition([2, 24]) + expect(editor.scrollLeft()).toBe 0 + + editor.setCursorScreenPosition([2, 25]) + expect(editor.scrollLeft()).toBe 0 + + editor.setCursorScreenPosition([2, 28]) + expect(editor.scrollLeft()).toBe 0 + + # moving left + editor.setCursorScreenPosition([2, 9]) + expect(editor.scrollLeft()).toBe 0 + + editor.setCursorScreenPosition([2, 8]) + expect(editor.scrollLeft()).toBe 0 + + editor.setCursorScreenPosition([2, 5]) + expect(editor.scrollLeft()).toBe 0 + + describe "when soft-wrap is on", -> + beforeEach -> + editor.setSoftWrap(true) + + it "does not scroll the buffer", -> + editor.width(charWidth * 30) + + # moving right + editor.setCursorScreenPosition([2, 24]) + expect(editor.scrollLeft()).toBe 0 + + editor.setCursorScreenPosition([2, 25]) + expect(editor.scrollLeft()).toBe 0 + + editor.setCursorScreenPosition([2, 28]) + expect(editor.scrollLeft()).toBe 0 + + # moving left + editor.setCursorScreenPosition([2, 9]) + expect(editor.scrollLeft()).toBe 0 + + editor.setCursorScreenPosition([2, 8]) + expect(editor.scrollLeft()).toBe 0 + + editor.setCursorScreenPosition([2, 5]) + expect(editor.scrollLeft()).toBe 0 + describe "when left is pressed on the first column", -> describe "when there is a previous line", -> it "wraps to the end of the previous line", -> diff --git a/src/atom/cursor.coffee b/src/atom/cursor.coffee index 841698afb..6aca92bce 100644 --- a/src/atom/cursor.coffee +++ b/src/atom/cursor.coffee @@ -128,7 +128,9 @@ class Cursor extends View @editor.scrollTop(desiredTop) autoScrollHorizontally: (position) -> - charsInView = @editor.lines.width() / @width() + return if @editor.softWrap + + charsInView = @editor.width() / @width() maxScrollMargin = Math.floor((charsInView - 1) / 2) scrollMargin = Math.min(@editor.hScrollMargin, maxScrollMargin) margin = scrollMargin * @width() diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index 54a8a2496..1f2b2a498 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -230,10 +230,13 @@ class Editor extends View setSoftWrap: (@softWrap) -> @setMaxLineLength() if @softWrap + @addClass 'soft-wrap' @_setMaxLineLength = => @setMaxLineLength() $(window).on 'resize', @_setMaxLineLength else $(window).off 'resize', @_setMaxLineLength + @removeClass 'soft-wrap' + clipScreenPosition: (screenPosition, options={}) -> @renderer.clipScreenPosition(screenPosition, options) diff --git a/static/editor.css b/static/editor.css index b6abe355b..63b4c07ff 100644 --- a/static/editor.css +++ b/static/editor.css @@ -12,6 +12,10 @@ -webkit-user-select: none; } +.editor.soft-wrap { + overflow-x: hidden; +} + .editor .content { display: -webkit-flexbox; } @@ -24,7 +28,7 @@ } .editor .gutter.drop-shadow { - -webkit-box-shadow: -2px 0px 10px 2px #222; + -webkit-box-shadow: -2px 0px 10px 2px #222; } .editor .lines {