Skip to content

Commit 161fae6

Browse files
bsyounessibdafna
authored andcommitted
Add event when hyperlinks are clicked
Signed-off-by: Youness Bennani <[email protected]>
1 parent 12a5ab9 commit 161fae6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

js/feathergrid.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
BasicSelectionModel,
88
CellRenderer,
99
RendererMap,
10+
Private,
11+
HyperlinkRenderer,
1012
} from '@lumino/datagrid';
1113
import { CommandRegistry } from '@lumino/commands';
1214
import { toArray } from '@lumino/algorithm';
@@ -24,6 +26,7 @@ import { DataGridModel as BackBoneModel } from './datagrid';
2426

2527
import '@lumino/default-theme/style/datagrid.css';
2628
import '../style/feathergrid.css';
29+
import { Platform } from '@lumino/domutils';
2730

2831
// Shorthand for a string->T mapping
2932
type Dict<T> = { [keys: string]: T };
@@ -132,6 +135,7 @@ class FeatherGridMouseHandler extends BasicMouseHandler {
132135
const hitRegion = hit.region;
133136
const buttonSize = HeaderRenderer.iconWidth * 1.5;
134137
const buttonPadding = HeaderRenderer.buttonPadding;
138+
let accel = Platform.accelKey(event);
135139

136140
this._mouseIsDown = true;
137141

@@ -169,6 +173,36 @@ class FeatherGridMouseHandler extends BasicMouseHandler {
169173
return;
170174
}
171175
}
176+
if (grid) {
177+
// Create cell config object.
178+
const config = Private.createCellConfigObject(grid, hit);
179+
180+
// Retrieve cell renderer.
181+
let renderer = grid.cellRenderers.get(config!);
182+
183+
// Only process hyperlink renderers.
184+
if (renderer instanceof HyperlinkRenderer) {
185+
// Use the url param if it exists.
186+
let url = CellRenderer.resolveOption(renderer.url, config!);
187+
// Otherwise assume cell value is the URL.
188+
if (!url) {
189+
const format = TextRenderer.formatGeneric();
190+
url = format(config!);
191+
}
192+
193+
// Emit message to open the hyperlink only if user hit Ctrl+Click.
194+
if (accel) {
195+
// Emit event that will be caught in case window.open is blocked
196+
window.postMessage({
197+
id: 'ipydatagrid::hyperlinkclick',
198+
url,
199+
}, '*');
200+
// Reset cursor default after clicking
201+
const cursor = this.cursorForHandle('none');
202+
grid.viewport.node.style.cursor = cursor;
203+
}
204+
}
205+
}
172206
//@ts-ignore added so we don't have to add basicmousehandler.ts fork
173207
super.onMouseDown(grid, event);
174208
}

0 commit comments

Comments
 (0)