1
1
import * as vscode from 'vscode'
2
2
import { OutputChannelLogger } from '../common/log'
3
3
import { EsbonioClient } from './client'
4
- import { Commands , Events , Notifications , Server } from '../common/constants'
4
+ import { Commands , Events , Notifications } from '../common/constants'
5
5
6
6
interface PreviewFileParams {
7
7
uri : string
@@ -14,6 +14,8 @@ interface PreviewFileResult {
14
14
15
15
export class PreviewManager {
16
16
17
+ private static readonly rstPreviewActiveContextKey =
18
+ 'restructuredtextPreviewFocus' ;
17
19
private panel ?: vscode . WebviewPanel
18
20
19
21
// The uri of the document currently shown in the preview pane
@@ -30,6 +32,9 @@ export class PreviewManager {
30
32
context . subscriptions . push (
31
33
vscode . commands . registerTextEditorCommand ( Commands . OPEN_PREVIEW_TO_SIDE , this . openPreviewToSide , this )
32
34
)
35
+ context . subscriptions . push (
36
+ vscode . commands . registerTextEditorCommand ( Commands . SHOW_SOURCE , this . showSource , this )
37
+ )
33
38
context . subscriptions . push (
34
39
vscode . window . onDidChangeActiveTextEditor ( this . onDidChangeEditor , this )
35
40
)
@@ -74,6 +79,19 @@ export class PreviewManager {
74
79
return await this . previewEditor ( editor , vscode . ViewColumn . Beside )
75
80
}
76
81
82
+ async showSource ( ) {
83
+ if ( ! this . currentUri ) {
84
+ return
85
+ }
86
+
87
+ let editor = findEditorFor ( this . currentUri )
88
+ if ( ! editor ) {
89
+ return
90
+ }
91
+
92
+ await vscode . window . showTextDocument ( editor . document , { preview : false } )
93
+ }
94
+
77
95
private scrollEditor ( params : { line : number } ) {
78
96
let editor = findEditorFor ( this . currentUri )
79
97
if ( ! editor ) {
@@ -133,6 +151,7 @@ export class PreviewManager {
133
151
134
152
this . currentUri = editor . document . uri
135
153
panel . webview . postMessage ( { 'show' : result . uri } )
154
+ this . setPreviewActiveContext ( true )
136
155
}
137
156
138
157
private getPanel ( placement : vscode . ViewColumn ) : vscode . WebviewPanel {
@@ -267,10 +286,19 @@ export class PreviewManager {
267
286
this . panel . onDidDispose ( ( ) => {
268
287
this . panel = undefined
269
288
this . currentUri = undefined
289
+ this . setPreviewActiveContext ( false )
270
290
} )
271
291
272
292
return this . panel
273
293
}
294
+
295
+ private setPreviewActiveContext ( value : boolean ) {
296
+ vscode . commands . executeCommand (
297
+ 'setContext' ,
298
+ PreviewManager . rstPreviewActiveContextKey ,
299
+ value
300
+ )
301
+ }
274
302
}
275
303
276
304
0 commit comments