From 1427dbf540dc349ac43bca25cb1171905132f252 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 15 Mar 2017 20:35:25 -0600 Subject: [PATCH] Make lines extend across the entire width of the scroller This ensures line decorations render properly, even when the content is narrower than the editor. --- spec/text-editor-component-spec.js | 11 ++++++++++- src/text-editor-component.js | 5 ++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/spec/text-editor-component-spec.js b/spec/text-editor-component-spec.js index 31498e4a0..8350251a9 100644 --- a/spec/text-editor-component-spec.js +++ b/spec/text-editor-component-spec.js @@ -231,6 +231,15 @@ describe('TextEditorComponent', () => { expect(lineNumberNodeForScreenRow(component, 1).classList.contains('folded')).toBe(true) }) + it('makes lines at least as wide as the scroller', async () => { + const {component, element, editor} = buildComponent() + const {scroller, gutterContainer} = component.refs + editor.setText('a') + await component.getNextUpdatePromise() + + expect(element.querySelector('.line').offsetWidth).toBe(scroller.offsetWidth - gutterContainer.offsetWidth) + }) + describe('mini editors', () => { it('adds the mini attribute', () => { const {element, editor} = buildComponent({mini: true}) @@ -395,7 +404,7 @@ describe('TextEditorComponent', () => { it('correctly autoscrolls after inserting a line that exceeds the current content width', async () => { const {component, element, editor} = buildComponent() const {scroller} = component.refs - element.style.width = component.getScrollWidth() + 'px' + element.style.width = component.getGutterContainerWidth() + component.measurements.longestLineWidth + 'px' await component.getNextUpdatePromise() editor.setCursorScreenPosition([0, Infinity]) diff --git a/src/text-editor-component.js b/src/text-editor-component.js index 2deb4d803..1c0511d70 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -1496,7 +1496,10 @@ class TextEditorComponent { if (this.getModel().isSoftWrapped()) { return this.getClientWidth() - this.getGutterContainerWidth() } else { - return Math.round(this.measurements.longestLineWidth + this.measurements.baseCharacterWidth) + return Math.max( + Math.round(this.measurements.longestLineWidth + this.measurements.baseCharacterWidth), + this.measurements.scrollerWidth - this.getGutterContainerWidth() + ) } }