mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Give highlight decorations unique id's to avoid potential React errors
Using the marker's id plus the decoration class can cause an error in the event we apply a decoration with the same class twice to the same marker. This is admittedly unlikely, but I think it's cleaner to just allocate unique id's for decoration objects.
This commit is contained in:
@@ -856,6 +856,12 @@ describe "EditorComponent", ->
|
||||
regions = node.querySelectorAll('.test-highlight .region')
|
||||
expect(regions.length).toBe 2
|
||||
|
||||
it "allows the same marker to be decorated with multiple highlights of the same class", ->
|
||||
editor.addDecorationForMarker(marker, type: 'highlight', class: 'test-highlight')
|
||||
waitsFor -> not component.decorationChangedImmediate?
|
||||
runs ->
|
||||
expect(node.querySelectorAll('.test-highlight').length).toBe 2
|
||||
|
||||
describe "hidden input field", ->
|
||||
it "renders the hidden input field at the position of the last cursor if the cursor is on screen and the editor is focused", ->
|
||||
editor.setVerticalScrollMargin(0)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
_ = require 'underscore-plus'
|
||||
|
||||
IdCounter = 1
|
||||
|
||||
module.exports =
|
||||
class Decoration
|
||||
@isType: (decoration, decorationType) ->
|
||||
@@ -9,6 +11,7 @@ class Decoration
|
||||
decorationType is decoration.type
|
||||
|
||||
constructor: (@marker, properties) ->
|
||||
@id = IdCounter++
|
||||
_.extend(this, properties)
|
||||
|
||||
getScreenRange: ->
|
||||
@@ -22,6 +25,7 @@ class Decoration
|
||||
|
||||
toObject: ->
|
||||
copy = {}
|
||||
copy.id = @id
|
||||
copy.valid = @isValid()
|
||||
copy.screenRange = @getScreenRange().copy()
|
||||
|
||||
|
||||
@@ -17,7 +17,8 @@ HighlightsComponent = React.createClass
|
||||
for markerId, decorations of highlightDecorations
|
||||
if decorations?
|
||||
for decoration in decorations
|
||||
highlightComponents.push(HighlightComponent({key: "#{markerId}-#{decoration.class}", decoration, editor, lineHeightInPixels}))
|
||||
highlightComponents.push(HighlightComponent({key: decoration.id, decoration, editor, lineHeightInPixels}))
|
||||
|
||||
highlightComponents
|
||||
|
||||
shouldComponentUpdate: (newProps) ->
|
||||
|
||||
Reference in New Issue
Block a user