From fd7772a653828c7367db636e84564d8ded63f10a Mon Sep 17 00:00:00 2001 From: probablycorey Date: Wed, 27 Mar 2013 15:07:30 -0700 Subject: [PATCH] Reset scrollLeft when setSoftWrapColumn is called When the scroll view is scrolled and overflow-x is set to 'hidden' the scroll view renders wrong. Setting scrollLeft to 0 fixes this problem. I'm unhappy with this solution, but it was a simple way to get the scroll view to update its layout. Closes #137 --- spec/app/editor-spec.coffee | 9 +++++++++ src/app/editor.coffee | 1 + 2 files changed, 10 insertions(+) diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index 160affc98..92d8b662b 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -977,6 +977,15 @@ describe "Editor", -> editor.setCursorScreenPosition([2, 5]) expect(editor.scrollView.scrollLeft()).toBe 0 + describe "when editor:toggle-soft-wrap is toggled", -> + describe "when the text exceeds the editor width and the scroll-view is horizontally scrolled", -> + it "wraps the text and renders properly", -> + editor.attachToDom(heightInLines: 30, widthInChars: 30) + editor.setText("Fashion axe umami jean shorts retro hashtag carles mumblecore. Photo booth skateboard Austin gentrify occupy ethical. Food truck gastropub keffiyeh, squid deep v pinterest literally sustainable salvia scenester messenger bag. Neutra messenger bag flexitarian four loko, shoreditch VHS pop-up tumblr seitan synth master cleanse. Marfa selvage ugh, raw denim authentic try-hard mcsweeney's trust fund fashion axe actually polaroid viral sriracha. Banh mi marfa plaid single-origin coffee. Pickled mumblecore lomo ugh bespoke.") + editor.scrollView.scrollLeft(editor.charWidth * 30) + editor.trigger "editor:toggle-soft-wrap" + expect(editor.scrollView.scrollLeft()).toBe 0 + describe "text rendering", -> describe "when all lines in the buffer are visible on screen", -> beforeEach -> diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 906b5fbd4..4ae1a6bd5 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -590,6 +590,7 @@ class Editor extends View @setSoftWrapColumn(softWrapColumn) if @attached if @activeEditSession.getSoftWrap() @addClass 'soft-wrap' + @scrollView.scrollLeft(0) @_setSoftWrapColumn = => @setSoftWrapColumn() $(window).on "resize.editor-#{@id}", @_setSoftWrapColumn else