| 4013 | } |
| 4014 | |
| 4015 | class HighlightsComponent { |
| 4016 | constructor (props) { |
| 4017 | this.props = {} |
| 4018 | this.element = document.createElement('div') |
| 4019 | this.element.className = 'highlights' |
| 4020 | this.element.style.contain = 'strict' |
| 4021 | this.element.style.position = 'absolute' |
| 4022 | this.element.style.overflow = 'hidden' |
| 4023 | this.element.style.userSelect = 'none' |
| 4024 | this.highlightComponentsByKey = new Map() |
| 4025 | this.update(props) |
| 4026 | } |
| 4027 | |
| 4028 | destroy () { |
| 4029 | this.highlightComponentsByKey.forEach((highlightComponent) => { |
| 4030 | highlightComponent.destroy() |
| 4031 | }) |
| 4032 | this.highlightComponentsByKey.clear() |
| 4033 | } |
| 4034 | |
| 4035 | update (newProps) { |
| 4036 | if (this.shouldUpdate(newProps)) { |
| 4037 | this.props = newProps |
| 4038 | const {height, width, lineHeight, highlightDecorations} = this.props |
| 4039 | |
| 4040 | this.element.style.height = height + 'px' |
| 4041 | this.element.style.width = width + 'px' |
| 4042 | |
| 4043 | const visibleHighlightDecorations = new Set() |
| 4044 | if (highlightDecorations) { |
| 4045 | for (let i = 0; i < highlightDecorations.length; i++) { |
| 4046 | const highlightDecoration = highlightDecorations[i] |
| 4047 | const highlightProps = Object.assign({lineHeight}, highlightDecorations[i]) |
| 4048 | |
| 4049 | let highlightComponent = this.highlightComponentsByKey.get(highlightDecoration.key) |
| 4050 | if (highlightComponent) { |
| 4051 | highlightComponent.update(highlightProps) |
| 4052 | } else { |
| 4053 | highlightComponent = new HighlightComponent(highlightProps) |
| 4054 | this.element.appendChild(highlightComponent.element) |
| 4055 | this.highlightComponentsByKey.set(highlightDecoration.key, highlightComponent) |
| 4056 | } |
| 4057 | |
| 4058 | highlightDecorations[i].flashRequested = false |
| 4059 | visibleHighlightDecorations.add(highlightDecoration.key) |
| 4060 | } |
| 4061 | } |
| 4062 | |
| 4063 | this.highlightComponentsByKey.forEach((highlightComponent, key) => { |
| 4064 | if (!visibleHighlightDecorations.has(key)) { |
| 4065 | highlightComponent.destroy() |
| 4066 | this.highlightComponentsByKey.delete(key) |
| 4067 | } |
| 4068 | }) |
| 4069 | } |
| 4070 | } |
| 4071 | |
| 4072 | shouldUpdate (newProps) { |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…