@@ -15,12 +15,10 @@ import * as ssh from 'ssh2'
15
15
const { changeprompt, changemodule, fullpath } =
16
16
client . import ( { msg : [ 'changeprompt' , 'changemodule' , 'resetprompt' ] , rpc : [ 'validatepath' , 'fullpath' ] } )
17
17
18
- let uriRegex
19
- if ( process . platform === 'win32' ) {
20
- uriRegex = / ( @ ( [ ^ \s ] + ) \s ( .* ?) \: ( \d + ) | ( ( ( [ a - z A - Z ] : | \. \. ? | \~ ) | ( [ ^ \0 < > \? \| \/ \s ! $ ` & * ( ) \[ \] + ' " : ; ] ) + ) ? ( ( \\ | \/ ) ( [ ^ \0 < > \? \| \/ \s ! $ ` & * ( ) \[ \] + ' " : ; ] ) + ) + ) ( \: \d + ) ? ) /
21
- } else {
22
- uriRegex = / ( @ ( [ ^ \s ] + ) \s ( .* ?) \: ( \d + ) | ( ( ( \. \. ? | \~ ) | ( [ ^ \0 \s ! $ ` & * ( ) \[ \] + ' " : ; \\ ] ) + ) ? ( \/ ( [ ^ \0 \s ! $ ` & * ( ) \[ \] + ' " : ; \\ ] ) + ) + ) ( \: \d + ) ? ) /
23
- }
18
+ const isWindows = process . platform === 'win32'
19
+ const uriRegex = isWindows ?
20
+ / ( @ ( [ ^ \s ] + ) \s ( .* ?) \: ( \d + ) | ( ( ( [ a - z A - Z ] : | \. \. ? | \~ ) | ( [ ^ \0 < > \? \| \/ \s ! $ ` & * ( ) \[ \] + ' " : ; ] ) + ) ? ( ( \\ | \/ ) ( [ ^ \0 < > \? \| \/ \s ! $ ` & * ( ) \[ \] + ' " : ; ] ) + ) + ) ( \: \d + ) ? ) / :
21
+ / ( @ ( [ ^ \s ] + ) \s ( .* ?) \: ( \d + ) | ( ( ( \. \. ? | \~ ) | ( [ ^ \0 \s ! $ ` & * ( ) \[ \] + ' " : ; \\ ] ) + ) ? ( \/ ( [ ^ \0 \s ! $ ` & * ( ) \[ \] + ' " : ; \\ ] ) + ) + ) ( \: \d + ) ? ) /
24
22
25
23
var whitelistedKeybindingsREPL = [ ]
26
24
var whitelistedKeybindingsTerminal = [ ]
@@ -52,6 +50,7 @@ export function activate (_ink) {
52
50
terminal = ink . InkTerminal . fromId ( 'julia-terminal' , terminalOptions ( ) )
53
51
terminal . setTitle ( 'REPL' , true )
54
52
terminal . onDidOpenLink ( hasKeyboardModifier )
53
+ terminal . registerTooltipHandler ( showTooltip , hideTooltip )
55
54
terminal . class = 'julia-terminal'
56
55
57
56
subs . add ( atom . config . observe ( 'julia-client.uiOptions.layouts.console.defaultLocation' , ( defaultLocation ) => {
@@ -157,6 +156,7 @@ export function activate (_ink) {
157
156
item . attachCustomKeyEventHandler ( ( e ) => handleKeybinding ( e , item ) )
158
157
addLinkHandler ( item . terminal )
159
158
item . onDidOpenLink ( hasKeyboardModifier )
159
+ item . registerTooltipHandler ( showTooltip , hideTooltip )
160
160
shellPty ( item . persistentState . cwd )
161
161
. then ( ( { pty, cwd} ) => item . attach ( pty , true , cwd ) )
162
162
. catch ( ( ) => { } )
@@ -179,6 +179,7 @@ function newTerminal (cwd) {
179
179
const term = ink . InkTerminal . fromId ( `terminal-julia-${ Math . floor ( Math . random ( ) * 10000000 ) } ` , terminalOptions ( ) )
180
180
term . attachCustomKeyEventHandler ( ( e ) => handleKeybinding ( e , term ) )
181
181
term . onDidOpenLink ( hasKeyboardModifier )
182
+ term . registerTooltipHandler ( showTooltip , hideTooltip )
182
183
addLinkHandler ( term . terminal )
183
184
shellPty ( cwd ) . then ( ( { pty, cwd} ) => {
184
185
term . attach ( pty , true , cwd )
@@ -195,6 +196,7 @@ function newRemoteTerminal () {
195
196
const term = ink . InkTerminal . fromId ( `terminal-remote-julia-${ Math . floor ( Math . random ( ) * 10000000 ) } ` , terminalOptions ( ) )
196
197
term . attachCustomKeyEventHandler ( ( e ) => handleKeybinding ( e , term ) )
197
198
term . onDidOpenLink ( hasKeyboardModifier )
199
+ term . registerTooltipHandler ( showTooltip , hideTooltip )
198
200
addLinkHandler ( term . terminal )
199
201
remotePty ( ) . then ( ( { pty, cwd, conf} ) => {
200
202
term . attach ( pty , true , cwd )
@@ -260,7 +262,10 @@ function handleLink (event, uri) {
260
262
pending : atom . config . get ( 'core.allowPendingPaneItems' )
261
263
} )
262
264
} else {
263
- urimatch = uri . match ( / ( [ ^ \: ] + ) (?: \: ( \d + ) ) ? / )
265
+ const matchregex = isWindows ?
266
+ / ( ( [ a - z A - Z ] \: ) ? [ ^ \: ] + ) (?: \: ( \d + ) ) ? / :
267
+ / ( [ ^ \: ] + ) (?: \: ( \d + ) ) ? /
268
+ urimatch = uri . match ( matchregex )
264
269
if ( urimatch ) {
265
270
const line = urimatch [ 2 ] !== null ? parseInt ( urimatch [ 2 ] ) : 0
266
271
ink . Opener . open ( urimatch [ 1 ] , line - 1 , {
@@ -274,9 +279,53 @@ function handleLink (event, uri) {
274
279
function addLinkHandler ( terminal ) {
275
280
terminal . registerLinkMatcher ( uriRegex , handleLink , {
276
281
willLinkActivate : ev => hasKeyboardModifier ( ev ) ,
282
+ tooltipCallback : ( ev , uri , location ) => showTooltip ( ev , uri , location , terminal ) ,
283
+ leaveCallback : ( ) => hideTooltip ( )
277
284
} )
278
285
}
279
286
287
+ let tooltip = null
288
+
289
+ function showTooltip ( event , uri , location , terminal ) {
290
+ hideTooltip ( )
291
+
292
+ if ( atom . config . get ( 'julia-client.consoleOptions.linkModifier' ) ) {
293
+ const el = document . createElement ( 'div' )
294
+ el . classList . add ( 'terminal-link-tooltip' )
295
+
296
+ const terminalRect = terminal . element . getBoundingClientRect ( )
297
+ const colWidth = terminalRect . width / terminal . cols
298
+ const rowHeight = terminalRect . height / terminal . rows
299
+
300
+ const leftPosition = location . start . x * colWidth + terminalRect . left
301
+ const topPosition = ( location . start . y - 1.5 ) * rowHeight + terminalRect . top
302
+
303
+ el . style . top = topPosition + 'px'
304
+ el . style . left = leftPosition + 'px'
305
+
306
+ el . innerText = ( process . platform == 'darwin' ? 'Cmd' : 'Ctrl' ) + '-Click to open link.'
307
+
308
+ tooltip = el
309
+ document . body . appendChild ( el )
310
+
311
+ return true
312
+ } else {
313
+ return false
314
+ }
315
+ }
316
+
317
+ function hideTooltip ( ) {
318
+ if ( tooltip ) {
319
+ try {
320
+ document . body . removeChild ( tooltip )
321
+ } catch ( err ) {
322
+
323
+ } finally {
324
+ tooltip = null
325
+ }
326
+ }
327
+ }
328
+
280
329
function handleKeybinding ( e , term , binds = whitelistedKeybindingsTerminal ) {
281
330
if ( process . platform !== 'win32' && e . keyCode === 13 && ( e . altKey || e . metaKey ) && e . type === 'keydown' ) {
282
331
// Meta-Enter doesn't work properly with xterm.js atm, so we send the right escape sequence ourselves:
0 commit comments