mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Support class property on overlay decorations
This commit is contained in:
committed by
Antonio Scandurra
parent
b6f71bc648
commit
47761a455e
@@ -900,10 +900,11 @@ describe('TextEditorComponent', () => {
|
||||
overlayElement.style.margin = '3px'
|
||||
overlayElement.style.backgroundColor = 'red'
|
||||
|
||||
editor.decorateMarker(marker, {type: 'overlay', item: overlayElement})
|
||||
const decoration = editor.decorateMarker(marker, {type: 'overlay', item: overlayElement, class: 'a'})
|
||||
await component.getNextUpdatePromise()
|
||||
|
||||
const overlayWrapper = overlayElement.parentElement
|
||||
expect(overlayWrapper.classList.contains('a')).toBe(true)
|
||||
expect(overlayWrapper.getBoundingClientRect().top).toBe(clientTopForLine(component, 5))
|
||||
expect(overlayWrapper.getBoundingClientRect().left).toBe(clientLeftForCharacter(component, 4, 25))
|
||||
|
||||
@@ -939,6 +940,16 @@ describe('TextEditorComponent', () => {
|
||||
overlayElement.style.height = 80 + 'px'
|
||||
await component.getNextUpdatePromise()
|
||||
expect(overlayWrapper.getBoundingClientRect().top).toBe(clientTopForLine(component, 5))
|
||||
|
||||
// Can update overlay wrapper class
|
||||
decoration.setProperties({type: 'overlay', item: overlayElement, class: 'b'})
|
||||
await component.getNextUpdatePromise()
|
||||
expect(overlayWrapper.classList.contains('a')).toBe(false)
|
||||
expect(overlayWrapper.classList.contains('b')).toBe(true)
|
||||
|
||||
decoration.setProperties({type: 'overlay', item: overlayElement})
|
||||
await component.getNextUpdatePromise()
|
||||
expect(overlayWrapper.classList.contains('b')).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -2355,6 +2355,7 @@ class OverlayComponent {
|
||||
constructor (props) {
|
||||
this.props = props
|
||||
this.element = document.createElement('atom-overlay')
|
||||
if (this.props.className != null) this.element.classList.add(this.props.className)
|
||||
this.element.appendChild(this.props.element)
|
||||
this.element.style.position = 'fixed'
|
||||
this.element.style.zIndex = 4
|
||||
@@ -2363,10 +2364,15 @@ class OverlayComponent {
|
||||
getElementResizeDetector().listenTo(this.element, this.props.didResize)
|
||||
}
|
||||
|
||||
update (props) {
|
||||
this.props = props
|
||||
update (newProps) {
|
||||
const oldProps = this.props
|
||||
this.props = newProps
|
||||
if (this.props.pixelTop != null) this.element.style.top = this.props.pixelTop + 'px'
|
||||
if (this.props.pixelLeft != null) this.element.style.left = this.props.pixelLeft + 'px'
|
||||
if (newProps.className !== oldProps.className) {
|
||||
if (oldProps.className != null) this.element.classList.remove(oldProps.className)
|
||||
if (newProps.className != null) this.element.classList.add(newProps.className)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user