Skip to content

Commit

Permalink
Fix crash in repositionTooltips when there are no tooltips
Browse files Browse the repository at this point in the history
FIX: Fix an issue that caused `repositionTooltips` to crash when it was
called on an editor without tooltips.

See https://discuss.codemirror.net/t/typeerror-cannot-read-properties-of-null-reading-maybemeasure/7094
  • Loading branch information
marijnh committed Sep 14, 2023
1 parent ddeed9d commit dc7509a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,5 +739,6 @@ export const closeHoverTooltips = closeHoverTooltipEffect.of(null)
/// re-positioning or CSS change affecting the editor) that could
/// invalidate the existing tooltip positions.
export function repositionTooltips(view: EditorView) {
view.plugin(tooltipPlugin)?.maybeMeasure()
let plugin = view.plugin(tooltipPlugin)
if (plugin) plugin.maybeMeasure()
}

2 comments on commit dc7509a

@bradymadden97
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these not the same semantically? I'm curious how this prevents a crash over the previous behavior.

@marijnh
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. a?.b() will not crash on the property dereference, but still try to call the resulting undefined value.

Please sign in to comment.