From 7f3160eba694128ab098d09ca0efefc3db0f2cdf Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 23 Sep 2015 09:57:06 +0200 Subject: [PATCH] Port .selectLinesContainingCursors() specs --- spec/text-editor-component-spec.coffee | 13 +++++++++++++ spec/text-editor-spec.coffee | 14 -------------- src/text-editor-element.coffee | 6 ++++++ 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/spec/text-editor-component-spec.coffee b/spec/text-editor-component-spec.coffee index 455d2cca1..41778003c 100644 --- a/spec/text-editor-component-spec.coffee +++ b/spec/text-editor-component-spec.coffee @@ -3393,6 +3393,19 @@ describe "TextEditorComponent", -> afterEach -> atom.themes.removeStylesheet("test") + describe "when selecting lines containing cursors", -> + it "autoscrolls to the selection", -> + editor.setCursorScreenPosition([5, 6]) + nextAnimationFrame() + + wrapperNode.scrollToTop() + nextAnimationFrame() + expect(wrapperNode.getScrollTop()).toBe 0 + + editor.selectLinesContainingCursors() + nextAnimationFrame() + expect(wrapperNode.getScrollBottom()).toBe (7 + 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 c73926b41..63d4c403d 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -1194,20 +1194,6 @@ describe "TextEditor", -> editor.selectLinesContainingCursors() expect(editor.getSelectedBufferRange()).toEqual [[1, 0], [4, 0]] - it "autoscrolls to the selection", -> - editor.setLineHeightInPixels(10) - editor.setDefaultCharWidth(10) - editor.setHeight(50) - editor.setWidth(50) - editor.setHorizontalScrollbarHeight(0) - editor.setCursorScreenPosition([5, 6]) - - editor.scrollToTop() - expect(editor.getScrollTop()).toBe 0 - - editor.selectLinesContainingCursors() - expect(editor.getScrollBottom()).toBe (7 + editor.getVerticalScrollMargin()) * 10 - describe ".selectToBeginningOfWord()", -> it "selects text from cusor position to beginning of word", -> editor.setCursorScreenPosition [0, 13] diff --git a/src/text-editor-element.coffee b/src/text-editor-element.coffee index 96e1d3969..d1fb14007 100644 --- a/src/text-editor-element.coffee +++ b/src/text-editor-element.coffee @@ -231,6 +231,12 @@ class TextEditorElement extends HTMLElement setScrollBottom: (scrollBottom) -> @component.setScrollBottom(scrollBottom) + scrollToTop: -> + @setScrollTop(0) + + scrollToBottom: -> + @setScrollBottom(Infinity) + getScrollTop: -> @component.getScrollTop()