Skip to content

Commit 68f1e35

Browse files
committed
Added basic code.
1 parent 3fb1b67 commit 68f1e35

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ dist
2121

2222
# Demo tutorial is populated during the build.
2323
lib/esbonio-extensions/esbonio/tutorial_demo
24+
code/.python-version

code/package.json

+11
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@
7272
"icon": "$(open-preview)",
7373
"category": "Esbonio"
7474
},
75+
{
76+
"command": "esbonio.preview.showSource",
77+
"title": "Show Source",
78+
"icon": "$(go-to-file)",
79+
"category": "Esbonio"
80+
},
7581
{
7682
"command": "esbonio.server.restart",
7783
"title": "Restart Language Server",
@@ -324,6 +330,11 @@
324330
"alt": "esbonio.preview.open",
325331
"group": "navigation",
326332
"when": "resourceLangId == restructuredtext"
333+
},
334+
{
335+
"command": "esbonio.preview.showSource",
336+
"group": "navigation",
337+
"when": "restructuredtextPreviewFocus"
327338
}
328339
]
329340
},

code/src/common/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export namespace Server {
55
export namespace Commands {
66
export const OPEN_PREVIEW = "esbonio.preview.open"
77
export const OPEN_PREVIEW_TO_SIDE = "esbonio.preview.openSide"
8+
export const SHOW_SOURCE = "esbonio.preview.showSource"
89
export const PREVIEW_FILE = "esbonio.server.previewFile"
910

1011
export const RESTART_SERVER = "esbonio.server.restart"

code/src/node/preview.ts

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as vscode from 'vscode'
22
import { OutputChannelLogger } from '../common/log'
33
import { EsbonioClient } from './client'
4-
import { Commands, Events, Notifications, Server } from '../common/constants'
4+
import { Commands, Events, Notifications } from '../common/constants'
55

66
interface PreviewFileParams {
77
uri: string
@@ -14,6 +14,8 @@ interface PreviewFileResult {
1414

1515
export class PreviewManager {
1616

17+
private static readonly rstPreviewActiveContextKey =
18+
'restructuredtextPreviewFocus';
1719
private panel?: vscode.WebviewPanel
1820

1921
// The uri of the document currently shown in the preview pane
@@ -30,6 +32,9 @@ export class PreviewManager {
3032
context.subscriptions.push(
3133
vscode.commands.registerTextEditorCommand(Commands.OPEN_PREVIEW_TO_SIDE, this.openPreviewToSide, this)
3234
)
35+
context.subscriptions.push(
36+
vscode.commands.registerTextEditorCommand(Commands.SHOW_SOURCE, this.showSource, this)
37+
)
3338
context.subscriptions.push(
3439
vscode.window.onDidChangeActiveTextEditor(this.onDidChangeEditor, this)
3540
)
@@ -74,6 +79,19 @@ export class PreviewManager {
7479
return await this.previewEditor(editor, vscode.ViewColumn.Beside)
7580
}
7681

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+
7795
private scrollEditor(params: { line: number }) {
7896
let editor = findEditorFor(this.currentUri)
7997
if (!editor) {
@@ -133,6 +151,7 @@ export class PreviewManager {
133151

134152
this.currentUri = editor.document.uri
135153
panel.webview.postMessage({ 'show': result.uri })
154+
this.setPreviewActiveContext(true)
136155
}
137156

138157
private getPanel(placement: vscode.ViewColumn): vscode.WebviewPanel {
@@ -267,10 +286,19 @@ export class PreviewManager {
267286
this.panel.onDidDispose(() => {
268287
this.panel = undefined
269288
this.currentUri = undefined
289+
this.setPreviewActiveContext(false)
270290
})
271291

272292
return this.panel
273293
}
294+
295+
private setPreviewActiveContext(value: boolean) {
296+
vscode.commands.executeCommand(
297+
'setContext',
298+
PreviewManager.rstPreviewActiveContextKey,
299+
value
300+
)
301+
}
274302
}
275303

276304

0 commit comments

Comments
 (0)