Hide scrollbars in mini editors

This commit is contained in:
Nathan Sobo
2017-04-13 14:21:21 -06:00
committed by Antonio Scandurra
parent e602b5c466
commit 336aa0f521
2 changed files with 29 additions and 6 deletions

View File

@@ -485,6 +485,20 @@ describe('TextEditorComponent', () => {
await component.getNextUpdatePromise()
expect(element.querySelector('.line').classList.contains('cursor-line')).toBe(false)
})
it('does not render scrollbars', async () => {
const {component, element, editor} = buildComponent({mini: true, autoHeight: false})
await setEditorWidthInCharacters(component, 10)
await setEditorHeightInLines(component, 1)
editor.setText('x'.repeat(20) + 'y'.repeat(20))
await component.getNextUpdatePromise()
expect(component.isHorizontalScrollbarVisible()).toBe(false)
expect(component.isVerticalScrollbarVisible()).toBe(false)
expect(component.refs.horizontalScrollbar).toBeUndefined()
expect(component.refs.verticalScrollbar).toBeUndefined()
})
})
describe('focus', () => {

View File

@@ -699,7 +699,7 @@ class TextEditorComponent {
}
renderDummyScrollbars () {
if (this.shouldRenderDummyScrollbars) {
if (this.shouldRenderDummyScrollbars && !this.props.model.isMini()) {
let scrollHeight, scrollTop, horizontalScrollbarHeight
let scrollWidth, scrollLeft, verticalScrollbarWidth, forceScrollbarVisible
@@ -1812,8 +1812,13 @@ class TextEditorComponent {
}
measureScrollbarDimensions () {
this.measurements.verticalScrollbarWidth = this.refs.verticalScrollbar.getRealScrollbarWidth()
this.measurements.horizontalScrollbarHeight = this.refs.horizontalScrollbar.getRealScrollbarHeight()
if (this.props.model.isMini()) {
this.measurements.verticalScrollbarWidth = 0
this.measurements.horizontalScrollbarHeight = 0
} else {
this.measurements.verticalScrollbarWidth = this.refs.verticalScrollbar.getRealScrollbarWidth()
this.measurements.horizontalScrollbarHeight = this.refs.horizontalScrollbar.getRealScrollbarHeight()
}
}
measureLongestLineWidth () {
@@ -2118,7 +2123,9 @@ class TextEditorComponent {
}
isVerticalScrollbarVisible () {
if (this.props.model.getAutoHeight()) return false
const {model} = this.props
if (model.isMini()) return false
if (model.getAutoHeight()) return false
if (this.getContentHeight() > this.getScrollContainerHeight()) return true
return (
this.getContentWidth() > this.getScrollContainerWidth() &&
@@ -2127,8 +2134,10 @@ class TextEditorComponent {
}
isHorizontalScrollbarVisible () {
if (this.props.model.getAutoWidth()) return false
if (this.props.model.isSoftWrapped()) return false
const {model} = this.props
if (model.isMini()) return false
if (model.getAutoWidth()) return false
if (model.isSoftWrapped()) return false
if (this.getContentWidth() > this.getScrollContainerWidth()) return true
return (
this.getContentHeight() > this.getScrollContainerHeight() &&