From c7cc404c4232256542a42b792cb22e6d97804dc9 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Fri, 28 Aug 2015 13:39:14 -0600 Subject: [PATCH] Simplify page-up/page-down MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We simply move the cursor up or down by the number of whole lines that fit on screen, allowing autoscroll to adjust the scroll position. This causes there to be a margin under the location to which we move the cursor, but I think it’s better to provide context and keep the autoscroll experience consistent when using the keyboard. --- spec/text-editor-spec.coffee | 13 +------------ src/text-editor.coffee | 6 +----- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index 739e3a3c4..7d9e17dc2 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -4535,26 +4535,21 @@ describe "TextEditor", -> expect(editor.getScrollBottom()).toBe (9 + editor.getVerticalScrollMargin()) * 10 describe ".pageUp/Down()", -> - it "scrolls one screen height up or down and moves the cursor one page length", -> + it "moves the cursor down one page length", -> editor.setLineHeightInPixels(10) editor.setHeight(50) - expect(editor.getScrollHeight()).toBe 130 expect(editor.getCursorBufferPosition().row).toBe 0 editor.pageDown() - expect(editor.getScrollTop()).toBe 50 expect(editor.getCursorBufferPosition().row).toBe 5 editor.pageDown() - expect(editor.getScrollTop()).toBe 80 expect(editor.getCursorBufferPosition().row).toBe 10 editor.pageUp() - expect(editor.getScrollTop()).toBe 30 expect(editor.getCursorBufferPosition().row).toBe 5 editor.pageUp() - expect(editor.getScrollTop()).toBe 0 expect(editor.getCursorBufferPosition().row).toBe 0 describe ".selectPageUp/Down()", -> @@ -4565,28 +4560,22 @@ describe "TextEditor", -> expect(editor.getCursorBufferPosition().row).toBe 0 editor.selectPageDown() - expect(editor.getScrollTop()).toBe 30 expect(editor.getSelectedBufferRanges()).toEqual [[[0, 0], [5, 0]]] editor.selectPageDown() - expect(editor.getScrollTop()).toBe 80 expect(editor.getSelectedBufferRanges()).toEqual [[[0, 0], [10, 0]]] editor.selectPageDown() - expect(editor.getScrollTop()).toBe 80 expect(editor.getSelectedBufferRanges()).toEqual [[[0, 0], [12, 2]]] editor.moveToBottom() editor.selectPageUp() - expect(editor.getScrollTop()).toBe 50 expect(editor.getSelectedBufferRanges()).toEqual [[[7, 0], [12, 2]]] editor.selectPageUp() - expect(editor.getScrollTop()).toBe 0 expect(editor.getSelectedBufferRanges()).toEqual [[[2, 0], [12, 2]]] editor.selectPageUp() - expect(editor.getScrollTop()).toBe 0 expect(editor.getSelectedBufferRanges()).toEqual [[[0, 0], [12, 2]]] describe '.get/setPlaceholderText()', -> diff --git a/src/text-editor.coffee b/src/text-editor.coffee index b8c2a76fb..1f5cc6363 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -2898,14 +2898,10 @@ class TextEditor extends Model setVerticalScrollbarWidth: (width) -> @displayBuffer.setVerticalScrollbarWidth(width) pageUp: -> - newScrollTop = @getScrollTop() - @getHeight() @moveUp(@getRowsPerPage()) - @setScrollTop(newScrollTop) pageDown: -> - newScrollTop = @getScrollTop() + @getHeight() @moveDown(@getRowsPerPage()) - @setScrollTop(newScrollTop) selectPageUp: -> @selectUp(@getRowsPerPage()) @@ -2915,7 +2911,7 @@ class TextEditor extends Model # Returns the number of rows per page getRowsPerPage: -> - Math.max(1, Math.ceil(@getHeight() / @getLineHeightInPixels())) + Math.max(1, Math.floor(@getHeight() / @getLineHeightInPixels())) ### Section: Config