Skip to content

Commit f8b5414

Browse files
committed
highlight links in ace editor only on direct link hover, fixes linkRegex
1 parent 2578385 commit f8b5414

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

pgmanage/app/static/pgmanage_frontend/src/ace_extras/ext-hoverlink.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
ace.define(
22
"ace/ext/hoverlink",
3-
[
4-
"require",
5-
"exports",
6-
"module",
7-
"ace/editor",
8-
"ace/config",
9-
"ace/range",
10-
],
3+
["require", "exports", "module", "ace/editor", "ace/config", "ace/range"],
114
function (require, exports, module) {
125
const Editor = require("ace/editor").Editor;
136
const Range = require("ace/range").Range;
14-
const linkRegex = /https?:\/\/www\.postgresql\.org\/docs\/[^\s"']+/g;
7+
const linkRegex = /(?<=\s)https?:\/\/www\.postgresql\.org\/docs\/[^\s"']+/g;
158
let hoverState = {
169
activeMarker: null,
1710
activeLink: null,
@@ -56,6 +49,23 @@ ace.define(
5649
return;
5750
}
5851

52+
// Get pixel position of the token range
53+
const screenStart = editor.renderer.textToScreenCoordinates(
54+
position.row,
55+
token.start
56+
);
57+
const screenEnd = editor.renderer.textToScreenCoordinates(
58+
position.row,
59+
token.start + token.value.length
60+
);
61+
62+
const mouseX = e.domEvent.clientX;
63+
64+
// Check if the mouse is within the link's pixel bounds
65+
if (mouseX < screenStart.pageX || mouseX > screenEnd.pageX) {
66+
clearHover(editor);
67+
return;
68+
}
5969
highlightLink(
6070
editor,
6171
position.row,

0 commit comments

Comments
 (0)