From 87c7a0ae30c8f2530dcb9d8e5bb7d5de6fa7be8d Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 23 Sep 2015 16:25:50 +0200 Subject: [PATCH] :green_heart: Fix some TextEditorComponent specs --- spec/text-editor-component-spec.coffee | 18 +++++++++--------- src/text-editor-component.coffee | 6 ++++++ src/text-editor-element.coffee | 6 ++++++ src/text-editor-presenter.coffee | 6 ++++++ 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/spec/text-editor-component-spec.coffee b/spec/text-editor-component-spec.coffee index 46e635088..74abcadb9 100644 --- a/spec/text-editor-component-spec.coffee +++ b/spec/text-editor-component-spec.coffee @@ -285,18 +285,18 @@ describe "TextEditorComponent", -> componentNode.style.width = gutterWidth + (30 * charWidth) + 'px' component.measureDimensions() nextAnimationFrame() - expect(editor.getScrollWidth()).toBeGreaterThan scrollViewNode.offsetWidth + expect(wrapperNode.getScrollWidth()).toBeGreaterThan scrollViewNode.offsetWidth # At the time of writing, using width: 100% to achieve the full-width # lines caused full-screen repaints after switching away from an editor # and back again Please ensure you don't cause a performance regression if # you change this behavior. - editorFullWidth = editor.getScrollWidth() + editor.getVerticalScrollbarWidth() + editorFullWidth = wrapperNode.getScrollWidth() + wrapperNode.getVerticalScrollbarWidth() for lineNode in lineNodes expect(lineNode.getBoundingClientRect().width).toBe(editorFullWidth) - componentNode.style.width = gutterWidth + editor.getScrollWidth() + 100 + 'px' + componentNode.style.width = gutterWidth + wrapperNode.getScrollWidth() + 100 + 'px' component.measureDimensions() nextAnimationFrame() scrollViewWidth = scrollViewNode.offsetWidth @@ -473,7 +473,7 @@ describe "TextEditorComponent", -> editor.setText "a line that wraps \n" editor.setSoftWrapped(true) nextAnimationFrame() - componentNode.style.width = 16 * charWidth + editor.getVerticalScrollbarWidth() + 'px' + componentNode.style.width = 16 * charWidth + wrapperNode.getVerticalScrollbarWidth() + 'px' component.measureDimensions() nextAnimationFrame() @@ -893,7 +893,7 @@ describe "TextEditorComponent", -> beforeEach -> editor.setSoftWrapped(true) nextAnimationFrame() - componentNode.style.width = 16 * charWidth + editor.getVerticalScrollbarWidth() + 'px' + componentNode.style.width = 16 * charWidth + wrapperNode.getVerticalScrollbarWidth() + 'px' component.measureDimensions() nextAnimationFrame() @@ -2244,7 +2244,7 @@ describe "TextEditorComponent", -> editor.setSoftWrapped(true) nextAnimationFrame() - componentNode.style.width = 21 * charWidth + editor.getVerticalScrollbarWidth() + 'px' + componentNode.style.width = 21 * charWidth + wrapperNode.getVerticalScrollbarWidth() + 'px' component.measureDimensions() nextAnimationFrame() @@ -2460,7 +2460,7 @@ describe "TextEditorComponent", -> wrapperNode.style.height = 4.5 * lineHeightInPixels + 'px' wrapperNode.style.width = 10 * charWidth + 'px' component.measureDimensions() - wrapperNode.setScrollBottom(editor.getScrollHeight()) + wrapperNode.setScrollBottom(wrapperNode.getScrollHeight()) nextAnimationFrame() lastLineNode = component.lineNodeForScreenRow(editor.getLastScreenRow()) bottomOfLastLine = lastLineNode.getBoundingClientRect().bottom @@ -2570,7 +2570,7 @@ describe "TextEditorComponent", -> component.measureDimensions() nextAnimationFrame() - expect(horizontalScrollbarNode.scrollWidth).toBe editor.getScrollWidth() + expect(horizontalScrollbarNode.scrollWidth).toBe wrapperNode.getScrollWidth() expect(horizontalScrollbarNode.style.left).toBe '0px' describe "mousewheel events", -> @@ -3101,7 +3101,7 @@ describe "TextEditorComponent", -> expect(componentNode.querySelectorAll('.line')).toHaveLength(6) gutterWidth = componentNode.querySelector('.gutter').offsetWidth - componentNode.style.width = gutterWidth + 14 * charWidth + editor.getVerticalScrollbarWidth() + 'px' + componentNode.style.width = gutterWidth + 14 * charWidth + wrapperNode.getVerticalScrollbarWidth() + 'px' atom.views.performDocumentPoll() nextAnimationFrame() expect(componentNode.querySelector('.line').textContent).toBe "var quicksort " diff --git a/src/text-editor-component.coffee b/src/text-editor-component.coffee index cb6329f05..1d265415c 100644 --- a/src/text-editor-component.coffee +++ b/src/text-editor-component.coffee @@ -388,6 +388,12 @@ class TextEditorComponent getScrollWidth: -> @presenter.getScrollWidth() + getVerticalScrollbarWidth: -> + @presenter.getVerticalScrollbarWidth() + + getHorizontalScrollbarHeight: -> + @presenter.getHorizontalScrollbarHeight() + onMouseDown: (event) => unless event.button is 0 or (event.button is 1 and process.platform is 'linux') # Only handle mouse down events for left mouse button on all platforms diff --git a/src/text-editor-element.coffee b/src/text-editor-element.coffee index eac2e7d5c..9d139eb11 100644 --- a/src/text-editor-element.coffee +++ b/src/text-editor-element.coffee @@ -258,6 +258,12 @@ class TextEditorElement extends HTMLElement getScrollWidth: -> @component.getScrollWidth() + getVerticalScrollbarWidth: -> + @component.getVerticalScrollbarWidth() + + getHorizontalScrollbarHeight: -> + @component.getHorizontalScrollbarHeight() + stopEventPropagation = (commandListeners) -> newCommandListeners = {} for commandName, commandListener of commandListeners diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index 77bb87f53..8dc9a90a9 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -1486,6 +1486,12 @@ class TextEditorPresenter getHorizontalScrollMarginInPixels: -> @model.getHorizontalScrollMargin() * @baseCharacterWidth + getVerticalScrollbarWidth: -> + @verticalScrollbarWidth + + getHorizontalScrollbarHeight: -> + @horizontalScrollbarHeight + commitPendingLogicalScrollPosition: -> {screenRange, options} = @pendingScrollLogicalPosition