diff --git a/lean4-infoview/src/infoview/collapsing.tsx b/lean4-infoview/src/infoview/collapsing.tsx index b53ad671f..14880cdea 100644 --- a/lean4-infoview/src/infoview/collapsing.tsx +++ b/lean4-infoview/src/infoview/collapsing.tsx @@ -32,18 +32,23 @@ interface DetailsProps { setOpenRef?: (_: React.Dispatch>) => void } -/** Like `
` but can be programatically revealed using `setOpenRef`. */ +/** Like `
` but can be programatically revealed using `setOpenRef`. + * The first child is placed inside the `` node. */ export function Details({ initiallyOpen, children: [summary, ...children], setOpenRef }: DetailsProps): JSX.Element { const [isOpen, setOpen] = React.useState(initiallyOpen === undefined ? false : initiallyOpen) - const setupEventListener = React.useCallback((node: HTMLDetailsElement | null) => { - if (node !== undefined && node !== null) { - node.addEventListener('toggle', () => setOpen(node.open)) - } - }, []) if (setOpenRef) setOpenRef(setOpen) return ( -
- {summary} +
+ { + if (!e.defaultPrevented) setOpen(!isOpen) + // See https://github.com/facebook/react/issues/15486#issuecomment-873516817 + e.preventDefault() + }} + > + {summary} + {isOpen && children}
) diff --git a/lean4-infoview/src/infoview/goalLocation.tsx b/lean4-infoview/src/infoview/goalLocation.tsx index 4c5c2bb1e..8a92155e9 100644 --- a/lean4-infoview/src/infoview/goalLocation.tsx +++ b/lean4-infoview/src/infoview/goalLocation.tsx @@ -109,6 +109,7 @@ export function useSelectableLocation(settings: SelectableLocationSettings): Sel if (settings.isSelectable && locs && e.shiftKey) { locs.setSelected(settings.loc, on => !on) e.stopPropagation() + e.preventDefault() return true } return false diff --git a/lean4-infoview/src/infoview/goals.tsx b/lean4-infoview/src/infoview/goals.tsx index e0405061e..b2389c7c5 100644 --- a/lean4-infoview/src/infoview/goals.tsx +++ b/lean4-infoview/src/infoview/goals.tsx @@ -403,7 +403,7 @@ export const FilteredGoals = React.memo( return (
(setOpenRef.current = r)} initiallyOpen={initiallyOpen}> - + <> {headerChildren} - +
{goals && }
diff --git a/lean4-infoview/src/infoview/info.tsx b/lean4-infoview/src/infoview/info.tsx index 0a45e75ad..bf47a5ad7 100644 --- a/lean4-infoview/src/infoview/info.tsx +++ b/lean4-infoview/src/infoview/info.tsx @@ -227,7 +227,7 @@ const InfoDisplayContent = React.memo((props: InfoDisplayContentProps) => { />
- Messages ({messages.length}) + <>Messages ({messages.length})
diff --git a/lean4-infoview/src/infoview/messages.tsx b/lean4-infoview/src/infoview/messages.tsx index 96e06a7d6..e3f980570 100644 --- a/lean4-infoview/src/infoview/messages.tsx +++ b/lean4-infoview/src/infoview/messages.tsx @@ -53,7 +53,7 @@ const MessageView = React.memo(({ uri, diag }: MessageViewProps) => { ) return (
- + {title} e.preventDefault()}> { title="copy message to clipboard" > - +
                     
@@ -192,7 +192,7 @@ export function AllMessages({ uri: uri0 }: { uri: DocumentUri }) {
     return (
         
             
(setOpenRef.current = r)} initiallyOpen={!config.autoOpenShowsGoal}> - + <> All Messages ({numDiags ?? diags.length}) - +
diff --git a/lean4-infoview/src/infoview/tooltips.tsx b/lean4-infoview/src/infoview/tooltips.tsx index 5509544d1..ba4a1f0f3 100644 --- a/lean4-infoview/src/infoview/tooltips.tsx +++ b/lean4-infoview/src/infoview/tooltips.tsx @@ -251,6 +251,7 @@ export function useHoverTooltip( clearTimeout() setState(state === 'pin' ? 'hide' : 'pin') e.stopPropagation() + e.preventDefault() } const onClick = (e: React.MouseEvent) => { diff --git a/lean4-infoview/src/infoview/traceExplorer.tsx b/lean4-infoview/src/infoview/traceExplorer.tsx index 28d694c35..6afc6e32f 100644 --- a/lean4-infoview/src/infoview/traceExplorer.tsx +++ b/lean4-infoview/src/infoview/traceExplorer.tsx @@ -44,6 +44,7 @@ function LazyTrace({ col, cls, msg }: { col: number; cls: string; msg: MessageDa void fetchTrace() setOpen(true) ev.stopPropagation() + ev.preventDefault() }} > [{cls}] > @@ -57,6 +58,7 @@ function LazyTrace({ col, cls, msg }: { col: number; cls: string; msg: MessageDa onClick={ev => { setOpen(false) ev.stopPropagation() + ev.preventDefault() }} > [{cls}] ∨ @@ -72,6 +74,7 @@ function LazyTrace({ col, cls, msg }: { col: number; cls: string; msg: MessageDa onClick={ev => { void fetchTrace() ev.stopPropagation() + ev.preventDefault() }} > [{cls}] Error (click to retry): @@ -134,6 +137,7 @@ function CollapsibleTraceNode(traceEmbed: TraceEmbed) { // Don't handle clicks within React portals nested in this div (notably, tooltips). if (!ev.currentTarget.contains(ev.target)) return ev.stopPropagation() + ev.preventDefault() if (!open) void fetchChildren() setOpen(o => !o) },