@codemirror/tooltip
Advanced tools
Comparing version 0.19.7 to 0.19.8
@@ -0,1 +1,7 @@ | ||
## 0.19.8 (2021-11-19) | ||
### Bug fixes | ||
Make automatic repositioning when tooltips go out of view more robust with an intersection observer. | ||
## 0.19.7 (2021-11-17) | ||
@@ -2,0 +8,0 @@ |
@@ -72,2 +72,3 @@ import { ViewPlugin, Direction, EditorView, logException } from '@codemirror/view'; | ||
this.inView = true; | ||
this.lastLayoutWrite = 0; | ||
let config = view.state.facet(tooltipConfig); | ||
@@ -80,4 +81,8 @@ this.position = config.position; | ||
this.manager = new TooltipViewManager(view, showTooltip, t => this.createTooltip(t)); | ||
this.maybeMeasure = this.maybeMeasure.bind(this); | ||
window.addEventListener("resize", this.maybeMeasure); | ||
this.intersectionObserver = typeof IntersectionObserver == "function" ? new IntersectionObserver(entries => { | ||
if (Date.now() > this.lastLayoutWrite - 20 && | ||
entries.length > 0 && entries[entries.length - 1].intersectionRatio < 1) | ||
this.maybeMeasure(); | ||
}, { threshold: [1] }) : null; | ||
this.observeIntersection(); | ||
this.maybeMeasure(); | ||
@@ -96,4 +101,14 @@ } | ||
} | ||
observeIntersection() { | ||
if (this.intersectionObserver) { | ||
this.intersectionObserver.disconnect(); | ||
for (let tooltip of this.manager.tooltipViews) | ||
this.intersectionObserver.observe(tooltip.dom); | ||
} | ||
} | ||
update(update) { | ||
let shouldMeasure = this.manager.update(update) || update.geometryChanged; | ||
let updated = this.manager.update(update); | ||
if (updated) | ||
this.observeIntersection(); | ||
let shouldMeasure = updated || update.geometryChanged; | ||
let newConfig = update.state.facet(tooltipConfig); | ||
@@ -137,5 +152,6 @@ if (newConfig.position != this.position) { | ||
destroy() { | ||
var _a; | ||
for (let { dom } of this.manager.tooltipViews) | ||
dom.remove(); | ||
window.removeEventListener("resize", this.maybeMeasure); | ||
(_a = this.intersectionObserver) === null || _a === void 0 ? void 0 : _a.disconnect(); | ||
} | ||
@@ -154,2 +170,3 @@ readMeasure() { | ||
writeMeasure(measured) { | ||
this.lastLayoutWrite = Date.now(); | ||
let { editor } = measured; | ||
@@ -156,0 +173,0 @@ let others = []; |
{ | ||
"name": "@codemirror/tooltip", | ||
"version": "0.19.7", | ||
"version": "0.19.8", | ||
"description": "Tooltip support for the CodeMirror code editor", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52043
1161