mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Ensure combined scroll margins are smaller than editor height.
This prevents jerky scrolling when the window is very short.
This commit is contained in:
@@ -44,29 +44,40 @@ describe "Editor", ->
|
||||
expect(editor.getPosition()).toEqual(row: 0, col: 0)
|
||||
|
||||
describe "vertical movement", ->
|
||||
describe "scroll margins", ->
|
||||
beforeEach ->
|
||||
editor.attachToDom()
|
||||
editor.focus()
|
||||
editor.scrollMargin = 3
|
||||
|
||||
fit "scrolls the buffer with the specified scroll margin when cursor approaches the end of the screen", ->
|
||||
editor.attachToDom()
|
||||
editor.focus()
|
||||
editor.scrollMargin = 3
|
||||
editor.height(editor.lineHeight * 10)
|
||||
it "scrolls the buffer with the specified scroll margin when cursor approaches the end of the screen", ->
|
||||
editor.height(editor.lineHeight * 10)
|
||||
|
||||
_.times 6, -> editor.moveDown()
|
||||
expect(editor.scrollTop()).toBe(0)
|
||||
_.times 6, -> editor.moveDown()
|
||||
expect(editor.scrollTop()).toBe(0)
|
||||
|
||||
editor.moveDown()
|
||||
expect(editor.scrollTop()).toBe(editor.lineHeight)
|
||||
editor.moveDown()
|
||||
expect(editor.scrollTop()).toBe(editor.lineHeight * 2)
|
||||
editor.moveDown()
|
||||
expect(editor.scrollTop()).toBe(editor.lineHeight)
|
||||
editor.moveDown()
|
||||
expect(editor.scrollTop()).toBe(editor.lineHeight * 2)
|
||||
|
||||
_.times 3, -> editor.moveUp()
|
||||
expect(editor.scrollTop()).toBe(editor.lineHeight * 2)
|
||||
_.times 3, -> editor.moveUp()
|
||||
expect(editor.scrollTop()).toBe(editor.lineHeight * 2)
|
||||
|
||||
editor.moveUp()
|
||||
expect(editor.scrollTop()).toBe(editor.lineHeight)
|
||||
editor.moveUp()
|
||||
expect(editor.scrollTop()).toBe(editor.lineHeight)
|
||||
|
||||
editor.moveUp()
|
||||
expect(editor.scrollTop()).toBe(0)
|
||||
editor.moveUp()
|
||||
expect(editor.scrollTop()).toBe(0)
|
||||
|
||||
it "sacrifices margins when there isn't enough height", ->
|
||||
editor.height(editor.lineHeight * 5)
|
||||
|
||||
_.times 3, -> editor.moveDown()
|
||||
expect(editor.scrollTop()).toBe(editor.lineHeight)
|
||||
|
||||
editor.moveUp()
|
||||
expect(editor.scrollTop()).toBe(0)
|
||||
|
||||
describe "when up is pressed on the first line", ->
|
||||
it "moves the cursor to the beginning of the line, but retains the goal column", ->
|
||||
|
||||
@@ -7,8 +7,8 @@ require 'window'
|
||||
|
||||
afterEach ->
|
||||
(new Native).resetMainMenu()
|
||||
# atom.globalKeymap.reset()
|
||||
# $('#jasmine-content').empty()
|
||||
atom.globalKeymap.reset()
|
||||
$('#jasmine-content').empty()
|
||||
|
||||
window.atom = new (require 'app')
|
||||
|
||||
|
||||
@@ -68,7 +68,11 @@ class Cursor extends Template
|
||||
position = @parentView.pixelPositionFromPoint(@point)
|
||||
@css(position)
|
||||
|
||||
margin = @parentView.scrollMargin * @height()
|
||||
linesInView = @parentView.height() / @height()
|
||||
|
||||
maxScrollMargin = Math.floor((linesInView - 1) / 2)
|
||||
scrollMargin = Math.min(@parentView.scrollMargin, maxScrollMargin)
|
||||
margin = scrollMargin * @height()
|
||||
desiredTop = position.top - margin
|
||||
desiredBottom = position.top + @height() + margin
|
||||
|
||||
|
||||
Reference in New Issue
Block a user