Skip to content

Commit

Permalink
Merge 6b2b4af into 68de152
Browse files Browse the repository at this point in the history
  • Loading branch information
ivoelbert committed Mar 14, 2024
2 parents 68de152 + 6b2b4af commit 9cf0a54
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
52 changes: 34 additions & 18 deletions packages/core/src/cells/uri-cell.tsx
Expand Up @@ -38,6 +38,32 @@ function getTextRect(
return { x, y, width, height };
}

function isOverLinkText(e: {
readonly cell: UriCell;
readonly posX: number;
readonly posY: number;
readonly bounds: Rectangle;
readonly theme: FullTheme;
}): boolean {
const { cell, bounds, posX, posY, theme } = e;
const txt = cell.displayData ?? cell.data;
if (cell.hoverEffect !== true || cell.onClickUri === undefined) return false;

const m = getMeasuredTextCache(txt, theme.baseFontFull);
if (m === undefined) return false;
const textRect = getTextRect(m, bounds, theme, cell.contentAlign);
return pointInRect(
{
x: textRect.x - 4,
y: textRect.y - 4,
width: textRect.width + 8,
height: textRect.height + 8,
},
posX,
posY
);
}

export const uriCellRenderer: InternalCellRenderer<UriCell> = {
getAccessibilityString: c => c.data?.toString() ?? "",
kind: GridCellKind.Uri,
Expand Down Expand Up @@ -82,26 +108,16 @@ export const uriCellRenderer: InternalCellRenderer<UriCell> = {
ctx.fillStyle = isLinky ? theme.linkColor : theme.textDark;
drawTextCell(a, txt, cell.contentAlign);
},
onSelect: e => {
if (isOverLinkText(e)) {
e.preventDefault();
}
},
onClick: a => {
const { cell, bounds, posX, posY, theme } = a;
const txt = cell.displayData ?? cell.data;
if (cell.hoverEffect !== true || cell.onClickUri === undefined) return;

const m = getMeasuredTextCache(txt, theme.baseFontFull);
if (m === undefined) return;
const textRect = getTextRect(m, bounds, theme, cell.contentAlign);
const didClick = pointInRect(
{
x: textRect.x - 4,
y: textRect.y - 4,
width: textRect.width + 8,
height: textRect.height + 8,
},
posX,
posY
);
const { cell } = a;
const didClick = isOverLinkText(a);
if (didClick) {
cell.onClickUri(a);
cell.onClickUri?.(a);
}
return undefined;
},
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/data-editor/stories/utils.tsx
Expand Up @@ -678,6 +678,10 @@ function getColumnsForCellTypes(): GridColumnWithMockingInfo[] {
kind: GridCellKind.Uri,
data: url,
allowOverlay: true,
hoverEffect: true,
onClickUri: () => {
window.open(url, "_blank");
},
};
},
},
Expand Down

0 comments on commit 9cf0a54

Please sign in to comment.