mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Support scrolling to buffer and screen positions
This commit is contained in:
@@ -1005,12 +1005,12 @@ describe "Editor", ->
|
||||
editor.addCursorAtBufferPosition([6,50])
|
||||
[cursor1, cursor2] = editor.getCursors()
|
||||
|
||||
spyOn(editor, 'scrollTo')
|
||||
spyOn(editor, 'scrollToPixelPosition')
|
||||
cursor1.setScreenPosition([10, 10])
|
||||
expect(editor.scrollTo).not.toHaveBeenCalled()
|
||||
expect(editor.scrollToPixelPosition).not.toHaveBeenCalled()
|
||||
|
||||
cursor2.setScreenPosition([11, 11])
|
||||
expect(editor.scrollTo).toHaveBeenCalled()
|
||||
expect(editor.scrollToPixelPosition).toHaveBeenCalled()
|
||||
|
||||
describe "when the last cursor exceeds the upper or lower scroll margins", ->
|
||||
describe "when the editor is taller than twice the vertical scroll margin", ->
|
||||
@@ -1396,7 +1396,7 @@ describe "Editor", ->
|
||||
describe "when lines are added", ->
|
||||
beforeEach ->
|
||||
editor.attachToDom(heightInLines: 5)
|
||||
spyOn(editor, "scrollTo")
|
||||
spyOn(editor, "scrollToPixelPosition")
|
||||
|
||||
describe "when the change precedes the first rendered row", ->
|
||||
it "inserts and removes rendered lines to account for upstream change", ->
|
||||
@@ -1448,7 +1448,7 @@ describe "Editor", ->
|
||||
describe "when lines are removed", ->
|
||||
beforeEach ->
|
||||
editor.attachToDom(heightInLines: 5)
|
||||
spyOn(editor, "scrollTo")
|
||||
spyOn(editor, "scrollToPixelPosition")
|
||||
|
||||
it "sets the rendered screen line's width to either the max line length or the scollView's width (whichever is greater)", ->
|
||||
maxLineLength = editor.maxScreenLineLength()
|
||||
@@ -1614,7 +1614,7 @@ describe "Editor", ->
|
||||
|
||||
describe "when lines are inserted", ->
|
||||
it "re-renders the correct line number range in the gutter", ->
|
||||
spyOn(editor, 'scrollTo')
|
||||
spyOn(editor, 'scrollToPixelPosition')
|
||||
editor.scrollTop(3 * editor.lineHeight)
|
||||
expect(editor.gutter.find('.line-number:first').text()).toBe '2'
|
||||
expect(editor.gutter.find('.line-number:last').text()).toBe '11'
|
||||
|
||||
@@ -497,7 +497,13 @@ class Editor extends View
|
||||
scrollToBottom: ->
|
||||
@scrollBottom(@screenLineCount() * @lineHeight)
|
||||
|
||||
scrollTo: (pixelPosition, options) ->
|
||||
scrollToBufferPosition: (bufferPosition, options) ->
|
||||
@scrollToPixelPosition(@pixelPositionForBufferPosition(bufferPosition), options)
|
||||
|
||||
scrollToScreenPosition: (screenPosition, options) ->
|
||||
@scrollToPixelPosition(@pixelPositionForScreenPosition(screenPosition), options)
|
||||
|
||||
scrollToPixelPosition: (pixelPosition, options) ->
|
||||
return unless @attached
|
||||
@scrollVertically(pixelPosition, options)
|
||||
@scrollHorizontally(pixelPosition)
|
||||
@@ -800,11 +806,11 @@ class Editor extends View
|
||||
|
||||
autoscroll: (options={}) ->
|
||||
for cursorView in @getCursorViews() when cursorView.needsAutoscroll()
|
||||
@scrollTo(cursorView.getPixelPosition()) unless options.suppressAutoScroll
|
||||
@scrollToPixelPosition(cursorView.getPixelPosition()) unless options.suppressAutoScroll
|
||||
cursorView.autoscrolled()
|
||||
|
||||
for selectionView in @getSelectionViews() when selectionView.needsAutoscroll()
|
||||
@scrollTo(selectionView.getCenterPixelPosition(), center: true)
|
||||
@scrollToPixelPosition(selectionView.getCenterPixelPosition(), center: true)
|
||||
selectionView.autoscrolled()
|
||||
|
||||
updateRenderedLines: ->
|
||||
@@ -1025,6 +1031,9 @@ class Editor extends View
|
||||
@renderedLines.find('.line').each (n) ->
|
||||
console.log n, $(this).text()
|
||||
|
||||
pixelPositionForBufferPosition: (position) ->
|
||||
@pixelPositionForScreenPosition(@screenPositionForBufferPosition(position))
|
||||
|
||||
pixelPositionForScreenPosition: (position) ->
|
||||
position = Point.fromObject(position)
|
||||
{ top: position.row * @lineHeight, left: position.column * @charWidth }
|
||||
|
||||
@@ -51,9 +51,7 @@ class OutlineView extends SelectList
|
||||
confirmed : ({position, name}) ->
|
||||
@cancel()
|
||||
editor = @rootView.getActiveEditor()
|
||||
screenPosition = editor.screenPositionForBufferPosition(position)
|
||||
pixelPosition = editor.pixelPositionForScreenPosition(screenPosition)
|
||||
editor.scrollTo(pixelPosition, center: true)
|
||||
editor.scrollToBufferPosition(position, center: true)
|
||||
editor.setCursorBufferPosition(position)
|
||||
|
||||
cancelled: ->
|
||||
|
||||
Reference in New Issue
Block a user