(msg: OutMessage)
| 268 | |
| 269 | // handle message produced by javascript inside the help page |
| 270 | private async handleMessage(msg: OutMessage) { |
| 271 | if (msg.message === 'linkClicked') { |
| 272 | // handle hyperlinks clicked in the webview |
| 273 | // normal navigation does not work in webviews (even on localhost) |
| 274 | const href: string = msg.href || ''; |
| 275 | const currentScrollY: number = Number(msg.scrollY) || 0; |
| 276 | console.log('Link clicked: ' + href); |
| 277 | |
| 278 | // remove first to path entries (if these are webview internal stuff): |
| 279 | const uri = vscode.Uri.parse(href); |
| 280 | const parts = uri.path.split('/'); |
| 281 | if (parts[0] !== 'library' && parts[0] !== 'doc') { |
| 282 | parts.shift(); |
| 283 | } |
| 284 | if (parts[0] !== 'library' && parts[0] !== 'doc') { |
| 285 | parts.shift(); |
| 286 | } |
| 287 | |
| 288 | // actual request path as used by R: |
| 289 | const requestPath = parts.join('/'); |
| 290 | |
| 291 | // retrieve helpfile for path: |
| 292 | const helpFile = await this.rHelp.getHelpFileForPath(requestPath); |
| 293 | |
| 294 | // if successful, show helpfile: |
| 295 | if (helpFile) { |
| 296 | if (uri.fragment) { |
| 297 | helpFile.hash = '#' + uri.fragment; |
| 298 | } else { |
| 299 | helpFile.scrollY = 0; |
| 300 | } |
| 301 | if (uri.path.endsWith('.pdf')) { |
| 302 | void this.openInExternalBrowser(helpFile); |
| 303 | } else if (uri.path.endsWith('.R')) { |
| 304 | const doc = await vscode.workspace.openTextDocument({ |
| 305 | language: 'r', |
| 306 | content: helpFile.html0 |
| 307 | }); |
| 308 | void vscode.window.showTextDocument(doc); |
| 309 | } else { |
| 310 | void this.showHelpFile(helpFile, true, currentScrollY); |
| 311 | } |
| 312 | } else{ |
| 313 | void vscode.window.showWarningMessage(`Did not find help page for path ${requestPath}`); |
| 314 | } |
| 315 | } else if (msg.message === 'mouseClick') { |
| 316 | // use the additional mouse buttons to go forward/backwards |
| 317 | const currentScrollY = Number(msg.scrollY) || 0; |
| 318 | const button: number = Number(msg.button) || 0; |
| 319 | if (button === 3) { |
| 320 | this._goBack(currentScrollY); |
| 321 | } else if (button === 4) { |
| 322 | this._goForward(currentScrollY); |
| 323 | } |
| 324 | } else if (msg.message === 'codeClicked') { |
| 325 | if (!msg.code) { |
| 326 | return; |
| 327 | } |
no test coverage detected