Merge pull request #1695 from atom/ns-fix-softwrap-with-scrollbars

When scrollbar is visible, account for it when soft wrapping lines
This commit is contained in:
Nathan Sobo
2014-03-05 01:52:19 +02:00
2 changed files with 16 additions and 1 deletions

View File

@@ -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 """
<style>
::-webkit-scrollbar { width: 15px; }
</style>
"""
setEditorHeightInLines(editorView, 5)
setEditorWidthInChars(editorView, 40)
expect(editor.lineForScreenRow(2).text.length).toBe 34
describe "gutter rendering", ->
beforeEach ->
editorView.attachToDom(heightInLines: 5.5)

View File

@@ -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