From 11612f3746ac3001efe28efb539276961b902776 Mon Sep 17 00:00:00 2001 From: tsnobip Date: Mon, 1 Dec 2025 09:42:36 +0100 Subject: [PATCH 1/2] set hoverTime to 100ms --- src/components/CodeMirror.res | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/CodeMirror.res b/src/components/CodeMirror.res index fa473e754..7af3fb121 100644 --- a/src/components/CodeMirror.res +++ b/src/components/CodeMirror.res @@ -178,9 +178,14 @@ module CM6 = { @module("@codemirror/view") external dropCursor: unit => extension = "dropCursor" + module HoverTooltipOptions = { + type t = {hoverTime?: int, hideOnChange?: bool} + } @module("@codemirror/view") - external hoverTooltip: ((editorView, int, Side.t) => null) => extension = - "hoverTooltip" + external hoverTooltip: ( + (editorView, int, Side.t) => null, + ~options: HoverTooltipOptions.t=?, + ) => extension = "hoverTooltip" module UpdateListener = { type update @@ -604,7 +609,7 @@ let createLinterExtension = (errors: array): CM6.extension => { } let createHoverHintExtension = (hoverHints: array) => { - CM6.EditorView.hoverTooltip((view, pos, _side) => { + CM6.EditorView.hoverTooltip(~options={hoverTime: 100}, (view, pos, _side) => { let doc = view->CM6.EditorView.state->CM6.EditorState.doc let {number: line, from} = doc->CM6.Text.lineAt(pos) let col = pos - from From 1355a6bc029bd5bd406c68460ce2bc1a19b1cb90 Mon Sep 17 00:00:00 2001 From: tsnobip Date: Mon, 1 Dec 2025 09:42:53 +0100 Subject: [PATCH 2/2] fix hover hint selection --- src/components/CodeMirror.res | 48 +++++++++++++++++++++++++++++----- src/components/CodeMirror.resi | 12 +++++---- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/components/CodeMirror.res b/src/components/CodeMirror.res index 7af3fb121..b4e0802c8 100644 --- a/src/components/CodeMirror.res +++ b/src/components/CodeMirror.res @@ -46,14 +46,35 @@ module Error = { } module HoverHint = { - type position = { - line: int, - col: int, + module Position = { + type t = { + line: int, + col: int, + } + let compareLineCol = (pos1, pos2) => { + if pos1.line < pos2.line { + Ordering.less + } else if pos1.line > pos2.line { + Ordering.greater + } // same line, compare column + else if pos1.col < pos2.col { + Ordering.less + } else if pos1.col > pos2.col { + Ordering.greater + } else { + Ordering.equal + } + } + // let \"<" = (pos1, pos2) => compareLineCol(pos1, pos2) === Ordering.less + let \"<=" = (pos1, pos2) => compareLineCol(pos1, pos2) !== Ordering.greater + // let \">" = (pos1, pos2) => compareLineCol(pos1, pos2) === Ordering.greater + let \">=" = (pos1, pos2) => compareLineCol(pos1, pos2) !== Ordering.less + // let \"==" = (pos1, pos2) => compareLineCol(pos1, pos2) === Ordering.equal } type t = { - start: position, - end: position, + start: Position.t, + end: Position.t, hint: string, } } @@ -613,8 +634,21 @@ let createHoverHintExtension = (hoverHints: array) => { let doc = view->CM6.EditorView.state->CM6.EditorState.doc let {number: line, from} = doc->CM6.Text.lineAt(pos) let col = pos - from - let found = hoverHints->Array.find(({start, end}) => { - line >= start.line && line <= end.line && col >= start.col && col <= end.col + let mousePos = {HoverHint.Position.line, col} + + let found = Array.reduce(hoverHints, None, (prev, currentHint) => { + open! HoverHint.Position + let currentHintIncludesMousePos = currentHint.start <= mousePos && currentHint.end >= mousePos + switch prev { + | None if currentHintIncludesMousePos => Some(currentHint) + | Some(prevHint) + if currentHintIncludesMousePos && + (currentHint.start >= prevHint.start && + currentHint.end <= prevHint.end) => + Some(currentHint) + | None + | Some(_) => prev + } }) switch found { | Some({hint, start, end}) => diff --git a/src/components/CodeMirror.resi b/src/components/CodeMirror.resi index 0637ab8ae..96d0ea221 100644 --- a/src/components/CodeMirror.resi +++ b/src/components/CodeMirror.resi @@ -18,14 +18,16 @@ module Error: { } module HoverHint: { - type position = { - line: int, - col: int, + module Position: { + type t = { + line: int, + col: int, + } } type t = { - start: position, - end: position, + start: Position.t, + end: Position.t, hint: string, } }