|
5 | 5 | import { Shortcut } from '@deephaven/components'; |
6 | 6 | import { IdeSession } from '@deephaven/jsapi-shim'; |
7 | 7 | import { assertNotNull } from '@deephaven/utils'; |
| 8 | +import { find as linkifyFind } from 'linkifyjs'; |
8 | 9 | import * as monaco from 'monaco-editor'; |
9 | 10 | import type { Environment } from 'monaco-editor'; |
10 | 11 | // @ts-ignore |
@@ -140,6 +141,10 @@ class MonacoUtils { |
140 | 141 | 'input.background': MonacoTheme['input-background'], |
141 | 142 | 'input.foreground': MonacoTheme['input-foreground'], |
142 | 143 | 'input.border': MonacoTheme['input-border'], |
| 144 | + 'textLink.foreground': MonacoTheme['text-link-foreground'], |
| 145 | + 'textLink.activeForeground': MonacoTheme['text-link-active-foreground'], |
| 146 | + 'editorLink.activeForeground': |
| 147 | + MonacoTheme['editor-link-active-foreground'], |
143 | 148 | }; |
144 | 149 |
|
145 | 150 | monaco.editor.defineTheme('dh-dark', { |
@@ -450,6 +455,28 @@ class MonacoUtils { |
450 | 455 | KeyCodeUtils.fromString(keyValue) |
451 | 456 | ); |
452 | 457 | } |
| 458 | + |
| 459 | + static provideLinks( |
| 460 | + model: monaco.editor.ITextModel |
| 461 | + ): { links: monaco.languages.ILink[] } { |
| 462 | + const newTokens: monaco.languages.ILink[] = []; |
| 463 | + |
| 464 | + for (let i = 1; i <= model.getLineCount(); i += 1) { |
| 465 | + const lineText = model.getLineContent(i); |
| 466 | + const tokens = linkifyFind(lineText); |
| 467 | + // map the tokens to the ranges - you know the line number now, use the token start/end as the startColumn/endColumn |
| 468 | + tokens.forEach(token => { |
| 469 | + newTokens.push({ |
| 470 | + url: token.href, |
| 471 | + range: new monaco.Range(i, token.start + 1, i, token.end + 1), |
| 472 | + }); |
| 473 | + }); |
| 474 | + } |
| 475 | + |
| 476 | + return { |
| 477 | + links: newTokens, |
| 478 | + }; |
| 479 | + } |
453 | 480 | } |
454 | 481 |
|
455 | 482 | export default MonacoUtils; |
0 commit comments