@@ -52,6 +52,7 @@ export function activate (_ink) {
52
52
terminal = ink . InkTerminal . fromId ( 'julia-terminal' , terminalOptions ( ) )
53
53
terminal . setTitle ( 'REPL' , true )
54
54
terminal . onDidOpenLink ( hasKeyboardModifier )
55
+ terminal . registerTooltipHandler ( showTooltip , hideTooltip )
55
56
terminal . class = 'julia-terminal'
56
57
57
58
subs . add ( atom . config . observe ( 'julia-client.uiOptions.layouts.console.defaultLocation' , ( defaultLocation ) => {
@@ -179,6 +180,7 @@ function newTerminal (cwd) {
179
180
const term = ink . InkTerminal . fromId ( `terminal-julia-${ Math . floor ( Math . random ( ) * 10000000 ) } ` , terminalOptions ( ) )
180
181
term . attachCustomKeyEventHandler ( ( e ) => handleKeybinding ( e , term ) )
181
182
term . onDidOpenLink ( hasKeyboardModifier )
183
+ term . registerTooltipHandler ( showTooltip , hideTooltip )
182
184
addLinkHandler ( term . terminal )
183
185
shellPty ( cwd ) . then ( ( { pty, cwd} ) => {
184
186
term . attach ( pty , true , cwd )
@@ -195,6 +197,7 @@ function newRemoteTerminal () {
195
197
const term = ink . InkTerminal . fromId ( `terminal-remote-julia-${ Math . floor ( Math . random ( ) * 10000000 ) } ` , terminalOptions ( ) )
196
198
term . attachCustomKeyEventHandler ( ( e ) => handleKeybinding ( e , term ) )
197
199
term . onDidOpenLink ( hasKeyboardModifier )
200
+ term . registerTooltipHandler ( showTooltip , hideTooltip )
198
201
addLinkHandler ( term . terminal )
199
202
remotePty ( ) . then ( ( { pty, cwd, conf} ) => {
200
203
term . attach ( pty , true , cwd )
@@ -274,9 +277,51 @@ function handleLink (event, uri) {
274
277
function addLinkHandler ( terminal ) {
275
278
terminal . registerLinkMatcher ( uriRegex , handleLink , {
276
279
willLinkActivate : ev => hasKeyboardModifier ( ev ) ,
280
+ tooltipCallback : ( ev , uri , location ) => showTooltip ( ev , uri , location , terminal ) ,
281
+ leaveCallback : ( ) => hideTooltip ( )
277
282
} )
278
283
}
279
284
285
+ let tooltip = null
286
+
287
+ function showTooltip ( event , uri , location , terminal ) {
288
+ if ( atom . config . get ( 'julia-client.consoleOptions.linkModifier' ) ) {
289
+ let el = document . createElement ( 'div' )
290
+ el . classList . add ( 'terminal-link-tooltip' )
291
+
292
+ const terminalRect = event . target . getBoundingClientRect ( )
293
+ const colWidth = terminalRect . width / terminal . cols
294
+ const rowHeight = terminalRect . height / terminal . rows
295
+
296
+ const leftPosition = location . start . x * colWidth + terminalRect . left
297
+ const topPosition = ( location . start . y - 1.5 ) * rowHeight + terminalRect . top
298
+
299
+ el . style . top = topPosition + 'px'
300
+ el . style . left = leftPosition + 'px'
301
+
302
+ el . innerText = ( process . platform == 'darwin' ? 'Cmd' : 'Ctrl' ) + '-Click to open link.'
303
+
304
+ tooltip = el
305
+ document . body . appendChild ( el )
306
+
307
+ return true
308
+ } else {
309
+ return false
310
+ }
311
+ }
312
+
313
+ function hideTooltip ( ) {
314
+ if ( tooltip ) {
315
+ try {
316
+ document . body . removeChild ( tooltip )
317
+ } catch ( err ) {
318
+
319
+ } finally {
320
+ tooltip = null
321
+ }
322
+ }
323
+ }
324
+
280
325
function handleKeybinding ( e , term , binds = whitelistedKeybindingsTerminal ) {
281
326
if ( process . platform !== 'win32' && e . keyCode === 13 && ( e . altKey || e . metaKey ) && e . type === 'keydown' ) {
282
327
// Meta-Enter doesn't work properly with xterm.js atm, so we send the right escape sequence ourselves:
0 commit comments