mirror of
https://github.com/atom/atom.git
synced 2026-02-12 15:45:23 -05:00
Selected results of a find operation are centered in the viewport
This commit is contained in:
@@ -495,24 +495,28 @@ class Editor extends View
|
||||
scrollToBottom: ->
|
||||
@scrollBottom(@screenLineCount() * @lineHeight)
|
||||
|
||||
scrollTo: (pixelPosition) ->
|
||||
scrollTo: (pixelPosition, options) ->
|
||||
return unless @attached
|
||||
@scrollVertically(pixelPosition)
|
||||
@scrollVertically(pixelPosition, options)
|
||||
@scrollHorizontally(pixelPosition)
|
||||
|
||||
scrollVertically: (pixelPosition) ->
|
||||
linesInView = @scrollView.height() / @lineHeight
|
||||
maxScrollMargin = Math.floor((linesInView - 1) / 2)
|
||||
scrollMargin = Math.min(@vScrollMargin, maxScrollMargin)
|
||||
margin = scrollMargin * @lineHeight
|
||||
desiredTop = pixelPosition.top - margin
|
||||
desiredBottom = pixelPosition.top + @lineHeight + margin
|
||||
|
||||
scrollVertically: (pixelPosition, {center}={}) ->
|
||||
scrollViewHeight = @scrollView.height()
|
||||
if desiredBottom > @scrollTop() + scrollViewHeight
|
||||
@scrollTop(desiredBottom - scrollViewHeight)
|
||||
else if desiredTop < @scrollTop()
|
||||
@scrollTop(desiredTop)
|
||||
|
||||
if center
|
||||
@scrollTop(pixelPosition.top - (scrollViewHeight / 2))
|
||||
else
|
||||
linesInView = @scrollView.height() / @lineHeight
|
||||
maxScrollMargin = Math.floor((linesInView - 1) / 2)
|
||||
scrollMargin = Math.min(@vScrollMargin, maxScrollMargin)
|
||||
margin = scrollMargin * @lineHeight
|
||||
desiredTop = pixelPosition.top - margin
|
||||
desiredBottom = pixelPosition.top + @lineHeight + margin
|
||||
|
||||
if desiredBottom > @scrollTop() + scrollViewHeight
|
||||
@scrollTop(desiredBottom - scrollViewHeight)
|
||||
else if desiredTop < @scrollTop()
|
||||
@scrollTop(desiredTop)
|
||||
|
||||
scrollHorizontally: (pixelPosition) ->
|
||||
return if @activeEditSession.getSoftWrap()
|
||||
@@ -792,6 +796,10 @@ class Editor extends View
|
||||
@scrollTo(cursorView.getPixelPosition()) unless options.suppressAutoScroll
|
||||
cursorView.needsAutoscroll = false
|
||||
|
||||
for selectionView in @getSelectionViews() when selectionView.selection.needsAutoscroll
|
||||
@scrollTo(selectionView.getCenterPixelPosition(), center: true)
|
||||
selectionView.selection.needsAutoscroll = false
|
||||
|
||||
updateRenderedLines: ->
|
||||
firstVisibleScreenRow = @getFirstVisibleScreenRow()
|
||||
lastVisibleScreenRow = @getLastVisibleScreenRow()
|
||||
|
||||
@@ -49,6 +49,13 @@ class SelectionView extends View
|
||||
@append(region)
|
||||
@regions.push(region)
|
||||
|
||||
getCenterPixelPosition: ->
|
||||
{ start, end } = @getScreenRange()
|
||||
startRow = start.row
|
||||
endRow = end.row
|
||||
endRow-- if end.column == 0
|
||||
@editor.pixelPositionForScreenPosition([((startRow + endRow + 1) / 2), start.column])
|
||||
|
||||
clearRegions: ->
|
||||
region.remove() for region in @regions
|
||||
@regions = []
|
||||
|
||||
@@ -63,11 +63,13 @@ class Selection
|
||||
{ start, end } = bufferRange
|
||||
[start, end] = [end, start] if options.reverse ? @isReversed()
|
||||
|
||||
@needsAutoscroll = options.autoscroll
|
||||
|
||||
@editSession.destroyFoldsIntersectingBufferRange(bufferRange) unless options.preserveFolds
|
||||
@placeAnchor() unless @anchor
|
||||
@modifySelection =>
|
||||
@anchor.setBufferPosition(start, options)
|
||||
@cursor.setBufferPosition(end, options)
|
||||
@anchor.setBufferPosition(start, autoscroll: false)
|
||||
@cursor.setBufferPosition(end, autoscroll: false)
|
||||
|
||||
getBufferRowRange: ->
|
||||
range = @getBufferRange()
|
||||
@@ -334,7 +336,11 @@ class Selection
|
||||
modifySelection: (fn) ->
|
||||
@retainSelection = true
|
||||
@placeAnchor() unless @anchor
|
||||
@anchor.pauseEvents()
|
||||
@cursor.pauseEvents()
|
||||
fn()
|
||||
@anchor.resumeEvents()
|
||||
@cursor.resumeEvents()
|
||||
@retainSelection = false
|
||||
|
||||
placeAnchor: ->
|
||||
|
||||
@@ -38,7 +38,7 @@ class CompositeCommand
|
||||
operation.destroy()
|
||||
|
||||
if bufferRanges.length and not currentCommand.preserveSelections
|
||||
editSession.setSelectedBufferRanges(bufferRanges)
|
||||
editSession.setSelectedBufferRanges(bufferRanges, autoscroll: true)
|
||||
|
||||
deferred.resolve({errorMessages})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user