fix: increase reliability of env hover tooltip

This commit is contained in:
Andrew Bastin
2022-02-12 02:16:21 +05:30
parent cd5b765ed1
commit 4296ee0251

View File

@@ -23,7 +23,8 @@ const HOPP_ENV_HIGHLIGHT_FOUND =
const HOPP_ENV_HIGHLIGHT_NOT_FOUND = "bg-red-400 text-red-50 hover:bg-red-600" const HOPP_ENV_HIGHLIGHT_NOT_FOUND = "bg-red-400 text-red-50 hover:bg-red-600"
const cursorTooltipField = (aggregateEnvs: AggregateEnvironment[]) => const cursorTooltipField = (aggregateEnvs: AggregateEnvironment[]) =>
hoverTooltip((view, pos, side) => { hoverTooltip(
(view, pos, side) => {
const { from, to, text } = view.state.doc.lineAt(pos) const { from, to, text } = view.state.doc.lineAt(pos)
// TODO: When Codemirror 6 allows this to work (not make the // TODO: When Codemirror 6 allows this to work (not make the
@@ -46,7 +47,9 @@ const cursorTooltipField = (aggregateEnvs: AggregateEnvironment[]) =>
if ( if (
(start === pos && side < 0) || (start === pos && side < 0) ||
(end === pos && side > 0) || (end === pos && side > 0) ||
!HOPP_ENVIRONMENT_REGEX.test(text.slice(start - from - 2, end - from + 2)) !HOPP_ENVIRONMENT_REGEX.test(
text.slice(start - from - 2, end - from + 2)
)
) )
return null return null
@@ -76,7 +79,12 @@ const cursorTooltipField = (aggregateEnvs: AggregateEnvironment[]) =>
return { dom } return { dom }
}, },
} }
}) },
// HACK: This is a hack to fix hover tooltip not coming half of the time
// https://github.com/codemirror/tooltip/blob/765c463fc1d5afcc3ec93cee47d72606bed27e1d/src/tooltip.ts#L622
// Still doesn't fix the not showing up some of the time issue, but this is atleast more consistent
{ hoverTime: 1 } as any
)
function checkEnv(env: string, aggregateEnvs: AggregateEnvironment[]) { function checkEnv(env: string, aggregateEnvs: AggregateEnvironment[]) {
const className = aggregateEnvs.find( const className = aggregateEnvs.find(