mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Use decorations to render selections
This commit is contained in:
@@ -26,6 +26,15 @@ class Decorations
|
||||
@decorationsCache[decorationType] = filteredDecorations
|
||||
@decorationsCache[decorationType]
|
||||
|
||||
decorationsByMarkerIdForType: (decorationType) ->
|
||||
filteredDecorations = {}
|
||||
for id, decorations of @decorationsByMarkerId
|
||||
for decoration in decorations
|
||||
if decoration.isType(decorationType)
|
||||
filteredDecorations[id] ?= []
|
||||
filteredDecorations[id].push decoration
|
||||
filteredDecorations
|
||||
|
||||
indexDecorationsByScreenRow: (decorationsByMarkerId) ->
|
||||
decorationsByScreenRow = {}
|
||||
for id, decorations of decorationsByMarkerId
|
||||
|
||||
@@ -93,7 +93,8 @@ EditorComponent = React.createClass
|
||||
lineHeightInPixels, defaultCharWidth
|
||||
}
|
||||
LinesComponent {
|
||||
ref: 'lines', editor, lineHeightInPixels, defaultCharWidth,
|
||||
ref: 'lines',
|
||||
editor, lineHeightInPixels, defaultCharWidth, decorations,
|
||||
showIndentGuide, renderedRowRange, @pendingChanges, scrollTop, scrollLeft, @scrollingVertically,
|
||||
selectionScreenRanges, scrollHeight, scrollWidth, mouseWheelScreenRow, invisibles,
|
||||
visible, scrollViewHeight
|
||||
|
||||
@@ -1260,6 +1260,7 @@ class Editor extends Model
|
||||
if selection.intersectsBufferRange(selectionBufferRange)
|
||||
return selection
|
||||
else
|
||||
@addDecorationForMarker(marker, type: 'highlight', class: 'selection')
|
||||
@emit 'selection-added', selection
|
||||
selection
|
||||
|
||||
|
||||
@@ -6,13 +6,13 @@ HighlightComponent = React.createClass
|
||||
displayName: 'HighlightComponent'
|
||||
|
||||
render: ->
|
||||
{editor, screenRange, lineHeightInPixels} = @props
|
||||
{start, end} = screenRange
|
||||
{editor, decoration, lineHeightInPixels} = @props
|
||||
{start, end} = decoration.getScreenRange()
|
||||
rowCount = end.row - start.row + 1
|
||||
startPixelPosition = editor.pixelPositionForScreenPosition(start)
|
||||
endPixelPosition = editor.pixelPositionForScreenPosition(end)
|
||||
|
||||
div className: 'selection',
|
||||
div className: "highlight #{decoration.class or ''}",
|
||||
if rowCount is 1
|
||||
@renderSingleLineRegions(startPixelPosition, endPixelPosition)
|
||||
else
|
||||
|
||||
@@ -8,18 +8,18 @@ HighlightsComponent = React.createClass
|
||||
displayName: 'HighlightsComponent'
|
||||
|
||||
render: ->
|
||||
div className: 'highlights', @renderSelections()
|
||||
div className: 'highlights', @renderHighlights()
|
||||
|
||||
renderSelections: ->
|
||||
{editor, selectionScreenRanges, lineHeightInPixels} = @props
|
||||
renderHighlights: ->
|
||||
{editor, decorations, lineHeightInPixels} = @props
|
||||
decorationsbyMarkerId = decorations.decorationsByMarkerIdForType('highlight')
|
||||
|
||||
selectionComponents = []
|
||||
for selectionId, screenRange of selectionScreenRanges
|
||||
selectionComponents.push(HighlightComponent({key: selectionId, screenRange, editor, lineHeightInPixels}))
|
||||
selectionComponents
|
||||
|
||||
componentWillMount: ->
|
||||
@selectionRanges = {}
|
||||
highlightComponents = []
|
||||
for markerId, decorations of decorationsbyMarkerId
|
||||
if decorations?
|
||||
for decoration in decorations
|
||||
highlightComponents.push(HighlightComponent({key: markerId + decoration.class, decoration, editor, lineHeightInPixels}))
|
||||
highlightComponents
|
||||
|
||||
shouldComponentUpdate: (newProps) ->
|
||||
not isEqualForProperties(newProps, @props, 'selectionScreenRanges', 'lineHeightInPixels', 'defaultCharWidth')
|
||||
not isEqualForProperties(newProps, @props, 'decorations', 'lineHeightInPixels', 'defaultCharWidth')
|
||||
|
||||
@@ -15,14 +15,14 @@ LinesComponent = React.createClass
|
||||
|
||||
render: ->
|
||||
if @isMounted()
|
||||
{editor, selectionScreenRanges, scrollTop, scrollLeft, scrollHeight, scrollWidth, lineHeightInPixels, defaultCharWidth, scrollViewHeight} = @props
|
||||
{editor, decorations, scrollTop, scrollLeft, scrollHeight, scrollWidth, lineHeightInPixels, defaultCharWidth, scrollViewHeight} = @props
|
||||
style =
|
||||
height: Math.max(scrollHeight, scrollViewHeight)
|
||||
width: scrollWidth
|
||||
WebkitTransform: "translate3d(#{-scrollLeft}px, #{-scrollTop}px, 0px)"
|
||||
|
||||
div {className: 'lines editor-colors', style},
|
||||
HighlightsComponent({editor, selectionScreenRanges, lineHeightInPixels, defaultCharWidth}) if @isMounted()
|
||||
HighlightsComponent({editor, decorations, lineHeightInPixels, defaultCharWidth}) if @isMounted()
|
||||
|
||||
componentWillMount: ->
|
||||
@measuredLines = new WeakSet
|
||||
|
||||
Reference in New Issue
Block a user