diff --git a/spec/text-editor-component-spec.coffee b/spec/text-editor-component-spec.coffee index 7dddb59a4..9562a7984 100644 --- a/spec/text-editor-component-spec.coffee +++ b/spec/text-editor-component-spec.coffee @@ -3381,7 +3381,7 @@ describe "TextEditorComponent", -> nextAnimationFrame() # Why does this set an incorrect width? :confused: - wrapperNode.style.width = "108px" + wrapperNode.style.width = "108px" # this should be 55px wrapperNode.style.height = 5.5 * 10 + "px" component.measureDimensions() nextAnimationFrame() @@ -3446,6 +3446,23 @@ describe "TextEditorComponent", -> nextAnimationFrame() expect(wrapperNode.getScrollTop()).toBe 75 + describe "when scrolled to cursor position", -> + it "scrolls the last cursor into view, centering around the cursor if possible and the 'center' option isn't false", -> + editor.setCursorScreenPosition([8, 8], autoscroll: false) + nextAnimationFrame() + expect(wrapperNode.getScrollTop()).toBe 0 + expect(wrapperNode.getScrollLeft()).toBe 0 + + wrapperNode.scrollToCursorPosition() + nextAnimationFrame() + expect(wrapperNode.getScrollTop()).toBe (8.8 * 10) - 30 + expect(wrapperNode.getScrollBottom()).toBe (8.3 * 10) + 30 + expect(wrapperNode.getScrollRight()).toBe (9 + editor.getHorizontalScrollMargin()) * 10 + + wrapperNode.setScrollTop(0) + wrapperNode.scrollToCursorPosition(center: false) + expect(editor.getScrollBottom()).toBe (8 + editor.getVerticalScrollMargin()) * 10 + describe "moving cursors", -> it "scrolls down when the last cursor gets closer than ::verticalScrollMargin to the bottom of the editor", -> expect(wrapperNode.getScrollTop()).toBe 0 diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index 9881546fa..b0cd021cb 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -4376,26 +4376,6 @@ describe "TextEditor", -> editor.normalizeTabsInBufferRange([[0, 0], [Infinity, Infinity]]) expect(editor.getText()).toBe ' ' - describe ".scrollToCursorPosition()", -> - it "scrolls the last cursor into view, centering around the cursor if possible and the 'center' option isn't false", -> - editor.setCursorScreenPosition([8, 8]) - editor.setLineHeightInPixels(10) - editor.setDefaultCharWidth(10) - editor.setHeight(60) - editor.setWidth(130) - editor.setHorizontalScrollbarHeight(0) - expect(editor.getScrollTop()).toBe 0 - expect(editor.getScrollLeft()).toBe 0 - - editor.scrollToCursorPosition() - expect(editor.getScrollTop()).toBe (8.5 * 10) - 30 - expect(editor.getScrollBottom()).toBe (8.5 * 10) + 30 - expect(editor.getScrollRight()).toBe (9 + editor.getHorizontalScrollMargin()) * 10 - - editor.setScrollTop(0) - editor.scrollToCursorPosition(center: false) - expect(editor.getScrollBottom()).toBe (9 + editor.getVerticalScrollMargin()) * 10 - describe ".pageUp/Down()", -> it "moves the cursor down one page length", -> editor.setLineHeightInPixels(10) diff --git a/src/text-editor-element.coffee b/src/text-editor-element.coffee index d1fb14007..eac2e7d5c 100644 --- a/src/text-editor-element.coffee +++ b/src/text-editor-element.coffee @@ -237,6 +237,9 @@ class TextEditorElement extends HTMLElement scrollToBottom: -> @setScrollBottom(Infinity) + scrollToCursorPosition: (options) -> + @getModel().getLastCursor().autoscroll(center: options?.center ? true) + getScrollTop: -> @component.getScrollTop()