From 834dd963ef204b1d763ae5aaf77a9cccb7a38b2e Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 4 Mar 2014 15:46:07 -0700 Subject: [PATCH 1/2] Subtract the scrollbar's width when calculating editor's width in chars Fixes #1342 --- src/editor-view.coffee | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/editor-view.coffee b/src/editor-view.coffee index adb19498e..4cb4ad984 100644 --- a/src/editor-view.coffee +++ b/src/editor-view.coffee @@ -667,11 +667,15 @@ class EditorView extends View @editor.setSoftWrap(not @editor.getSoftWrap()) calculateWidthInChars: -> - Math.floor(@scrollView.width() / @charWidth) + Math.floor((@scrollView.width() - @getScrollbarWidth()) / @charWidth) calculateHeightInLines: -> Math.ceil($(window).height() / @lineHeight) + getScrollbarWidth: -> + scrollbarElement = @verticalScrollbar[0] + scrollbarElement.offsetWidth - scrollbarElement.clientWidth + # Public: Enables/disables soft wrap on the editor. # # softWrap - A {Boolean} which, if `true`, enables soft wrap From e1bc62dae34a20e4230ef63e7f3c78becf531ba5 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 4 Mar 2014 16:45:50 -0700 Subject: [PATCH 2/2] Add a spec for line wrapping in the presence of legacy scrollbars --- spec/editor-view-spec.coffee | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/editor-view-spec.coffee b/spec/editor-view-spec.coffee index 33db23b42..60a014e47 100644 --- a/spec/editor-view-spec.coffee +++ b/spec/editor-view-spec.coffee @@ -1806,6 +1806,17 @@ describe "EditorView", -> runs -> expect(editor.getSoftWrapColumn()).toBeLessThan previousSoftWrapColumn + it "accounts for the width of the scrollbar if there is one", -> + # force the scrollbar to always be visible, regardless of OS visibility setting + $('#jasmine-content').prepend """ + + """ + setEditorHeightInLines(editorView, 5) + setEditorWidthInChars(editorView, 40) + expect(editor.lineForScreenRow(2).text.length).toBe 34 + describe "gutter rendering", -> beforeEach -> editorView.attachToDom(heightInLines: 5.5)