Skip to content

Commit 55af1c1

Browse files
author
Nathan Sobo
committed
Respect horizontal scrollbar when rendering the vertical, and vice versa
We set overflow to hidden in the opposite scroll direction only if we can't actually scroll in that direction, causing the white square where neither scrollbar overlaps to appear at the lower right corner.
1 parent 1ad394b commit 55af1c1

File tree

7 files changed

+56
-13
lines changed

7 files changed

+56
-13
lines changed

spec/editor-component-spec.coffee

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,26 @@ describe "EditorComponent", ->
547547
bottomOfEditor = node.getBoundingClientRect().bottom
548548
expect(bottomOfLastLine).toBe bottomOfEditor
549549

550+
it "assigns the overflow to 'hidden' in the opposite direction unless the editor scrollable in that direction", ->
551+
expect(verticalScrollbarNode.style.overflowX).toBe 'hidden'
552+
expect(horizontalScrollbarNode.style.overflowY).toBe 'hidden'
553+
return
554+
555+
node.style.height = 4.5 * lineHeightInPixels + 'px'
556+
component.measureHeightAndWidth()
557+
expect(verticalScrollbarNode.style.overflowX).toBe 'hidden'
558+
expect(horizontalScrollbarNode.style.overflowY).toBe ''
559+
560+
node.style.width = 10 * charWidth + 'px'
561+
component.measureHeightAndWidth()
562+
expect(verticalScrollbarNode.style.overflowX).toBe ''
563+
expect(horizontalScrollbarNode.style.overflowY).toBe ''
564+
565+
node.style.height = 20 * lineHeightInPixels + 'px'
566+
component.measureHeightAndWidth()
567+
expect(verticalScrollbarNode.style.overflowX).toBe ''
568+
expect(horizontalScrollbarNode.style.overflowY).toBe 'hidden'
569+
550570
describe "when a mousewheel event occurs on the editor", ->
551571
it "updates the horizontal or vertical scrollbar depending on which delta is greater (x or y)", ->
552572
node.style.height = 4.5 * lineHeightInPixels + 'px'

src/display-buffer.coffee

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,14 @@ class DisplayBuffer extends Model
123123
horizontallyScrollable: ->
124124
not @getSoftWrap() and @getScrollWidth() > @getWidth()
125125

126+
verticallyScrollable: ->
127+
@getScrollHeight() > @getClientHeight()
128+
126129
getHorizontalScrollbarHeight: -> 15
127130

128-
getWidth: -> @width ? @getScrollWidth()
131+
getWidth: ->
132+
@width ? @getScrollWidth()
133+
129134
setWidth: (newWidth) ->
130135
oldWidth = @width
131136
@width = newWidth
@@ -149,6 +154,8 @@ class DisplayBuffer extends Model
149154
setScrollLeft: (scrollLeft) ->
150155
if @manageScrollPosition
151156
@scrollLeft = Math.max(0, Math.min(@getScrollWidth() - @getWidth(), scrollLeft))
157+
console.log @scrollLeft
158+
@scrollLeft
152159
else
153160
@scrollLeft = scrollLeft
154161

src/editor-component.coffee

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ EditorComponent = React.createClass
5555
onScroll: @onVerticalScroll
5656
scrollTop: scrollTop
5757
scrollHeight: scrollHeight
58+
scrollableInOppositeDirection: editor.horizontallyScrollable() if @isMounted()
5859

5960
ScrollbarComponent
6061
ref: 'horizontalScrollbar'
@@ -63,6 +64,7 @@ EditorComponent = React.createClass
6364
onScroll: @onHorizontalScroll
6465
scrollLeft: scrollLeft
6566
scrollWidth: scrollWidth
67+
scrollableInOppositeDirection: editor.verticallyScrollable() if @isMounted()
6668

6769
getRenderedRowRange: ->
6870
renderedRowRange = @props.editor.getVisibleRowRange()

src/editor-scroll-view-component.coffee

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,19 @@ EditorScrollViewComponent = React.createClass
182182
measureHeightAndWidth: ->
183183
return unless @isMounted()
184184

185-
node = @getDOMNode()
186-
computedStyle = getComputedStyle(node)
187185
{editor} = @props
186+
node = @getDOMNode()
187+
editorNode = node.parentNode
188+
{position} = getComputedStyle(editorNode)
189+
{width, height} = editorNode.style
188190

189-
unless computedStyle.height is '0px'
190-
clientHeight = node.clientHeight
191+
if position is 'absolute' or height
192+
clientHeight = node.clientHeight
191193
editor.setHeight(clientHeight) if clientHeight > 0
192194

193-
unless computedStyle.width is '0px'
195+
if position is 'absolute' or width
194196
clientWidth = node.clientWidth
195-
editor.setWidth(clientWidth) if clientHeight > 0
197+
editor.setWidth(clientWidth) if clientWidth > 0
196198

197199
focus: ->
198200
@refs.input.focus()

src/editor.coffee

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,6 +1838,8 @@ class Editor extends Model
18381838
setHeight: (height) -> @displayBuffer.setHeight(height)
18391839
getHeight: -> @displayBuffer.getHeight()
18401840

1841+
getClientHeight: -> @displayBuffer.getClientHeight()
1842+
18411843
setWidth: (width) -> @displayBuffer.setWidth(width)
18421844
getWidth: -> @displayBuffer.getWidth()
18431845

@@ -1876,6 +1878,10 @@ class Editor extends Model
18761878

18771879
scrollToBufferPosition: (bufferPosition) -> @displayBuffer.scrollToBufferPosition(bufferPosition)
18781880

1881+
horizontallyScrollable: -> @displayBuffer.horizontallyScrollable()
1882+
1883+
verticallyScrollable: -> @displayBuffer.verticallyScrollable()
1884+
18791885
# Deprecated: Call {::joinLines} instead.
18801886
joinLine: ->
18811887
deprecate("Use Editor::joinLines() instead")

src/scrollbar-component.coffee

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
React = require 'react'
22
{div} = require 'reactionary'
3-
{isEqualForProperties} = require 'underscore-plus'
3+
{extend, isEqualForProperties} = require 'underscore-plus'
44

55
module.exports =
66
ScrollbarComponent = React.createClass
77
render: ->
8-
{orientation, className, scrollHeight, scrollWidth} = @props
8+
{orientation, className, scrollHeight, scrollWidth, scrollableInOppositeDirection} = @props
99

10-
div {className, @onScroll},
10+
style = {}
11+
switch orientation
12+
when 'vertical'
13+
style.overflowX = 'hidden' unless scrollableInOppositeDirection
14+
when 'horizontal'
15+
style.overflowY = 'hidden' unless scrollableInOppositeDirection
16+
17+
div {className, style, @onScroll},
1118
switch orientation
1219
when 'vertical'
1320
div className: 'scrollbar-content', style: {height: scrollHeight}
@@ -23,9 +30,9 @@ ScrollbarComponent = React.createClass
2330
shouldComponentUpdate: (newProps) ->
2431
switch @props.orientation
2532
when 'vertical'
26-
not isEqualForProperties(newProps, @props, 'scrollHeight', 'scrollTop')
33+
not isEqualForProperties(newProps, @props, 'scrollHeight', 'scrollTop', 'scrollableInOppositeDirection')
2734
when 'horizontal'
28-
not isEqualForProperties(newProps, @props, 'scrollWidth', 'scrollLeft')
35+
not isEqualForProperties(newProps, @props, 'scrollWidth', 'scrollLeft', 'scrollableInOppositeDirection')
2936

3037
componentDidUpdate: ->
3138
{orientation, scrollTop, scrollLeft} = @props

static/editor.less

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
height: 15px;
2626
overflow-x: auto;
27-
overflow-y: hidden;
2827
z-index: 3;
2928

3029
.scrollbar-content {

0 commit comments

Comments
 (0)