mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Only autoscroll selections to center if they are offscreen
This commit is contained in:
@@ -941,10 +941,14 @@ describe "Editor", ->
|
||||
expect(editor.scrollTop()).toBeGreaterThan(0)
|
||||
|
||||
describe "when the selected buffer range is assigned with the autoscroll option set to true", ->
|
||||
it "centers the selection in the viewport if possible", ->
|
||||
setEditorHeightInLines(editor, 8)
|
||||
it "centers the selection in the viewport if its vertical center is currently offscreen", ->
|
||||
setEditorHeightInLines(editor, 4)
|
||||
|
||||
editor.setSelectedBufferRange([[2, 0], [4, 0]], autoscroll: true)
|
||||
expect(editor.scrollTop()).toBe 0
|
||||
|
||||
editor.setSelectedBufferRange([[6, 0], [8, 0]], autoscroll: true)
|
||||
expect(editor.scrollTop()).toBe 3 * editor.lineHeight
|
||||
expect(editor.scrollTop()).toBe 5 * editor.lineHeight
|
||||
|
||||
describe "cursor rendering", ->
|
||||
describe "when the cursor moves", ->
|
||||
|
||||
@@ -502,9 +502,14 @@ class Editor extends View
|
||||
|
||||
scrollVertically: (pixelPosition, {center}={}) ->
|
||||
scrollViewHeight = @scrollView.height()
|
||||
scrollTop = @scrollTop()
|
||||
scrollBottom = scrollTop + scrollViewHeight
|
||||
|
||||
if center
|
||||
@scrollTop(pixelPosition.top - (scrollViewHeight / 2))
|
||||
console.log scrollTop, pixelPosition.top, scrollBottom
|
||||
|
||||
unless scrollTop < pixelPosition.top < scrollBottom
|
||||
@scrollTop(pixelPosition.top - (scrollViewHeight / 2))
|
||||
else
|
||||
linesInView = @scrollView.height() / @lineHeight
|
||||
maxScrollMargin = Math.floor((linesInView - 1) / 2)
|
||||
@@ -512,10 +517,9 @@ class Editor extends View
|
||||
margin = scrollMargin * @lineHeight
|
||||
desiredTop = pixelPosition.top - margin
|
||||
desiredBottom = pixelPosition.top + @lineHeight + margin
|
||||
|
||||
if desiredBottom > @scrollTop() + scrollViewHeight
|
||||
if desiredBottom > scrollBottom
|
||||
@scrollTop(desiredBottom - scrollViewHeight)
|
||||
else if desiredTop < @scrollTop()
|
||||
else if desiredTop < scrollTop
|
||||
@scrollTop(desiredTop)
|
||||
|
||||
scrollHorizontally: (pixelPosition) ->
|
||||
|
||||
Reference in New Issue
Block a user