Repository navigation
Expand file tree
/
Copy pathextension.js
More file actions
60 lines (49 loc) · 1.84 KB
/
Copy pathextension.js
File metadata and controls
60 lines (49 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const vscode = require('vscode');
const { buildPreviewHtml } = require('./preview');
const previewType = 'bbcode.preview.editor';
function openPreviewToSide() {
const editor = vscode.window.activeTextEditor;
if (!editor || editor.document.languageId !== 'bbcode') {
vscode.window.showInformationMessage('Open a .bbcode file to show its preview.');
return;
}
return vscode.commands.executeCommand(
'vscode.openWith', editor.document.uri, previewType,
{ viewColumn: vscode.ViewColumn.Beside, preserveFocus: true }
);
}
function resolveCustomTextEditor(document, panel) {
panel.webview.options = { enableScripts: false, localResourceRoots: [] };
const update = () => {
panel.webview.html = buildPreviewHtml(document.getText());
};
update();
const changeSubscription = vscode.workspace.onDidChangeTextDocument((event) => {
if (event.document === document) {
update();
}
});
panel.onDidDispose(() => changeSubscription.dispose());
}
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
context.subscriptions.push(
vscode.window.registerCustomEditorProvider(previewType, { resolveCustomTextEditor },
{ supportsMultipleEditorsPerDocument: true }),
vscode.commands.registerCommand('bbcode.preview', openPreviewToSide),
vscode.commands.registerCommand('bbcode.reopenAsPreview', () =>
vscode.commands.executeCommand('reopenActiveEditorWith', previewType)),
vscode.commands.registerCommand('bbcode.reopenAsSource', () =>
vscode.commands.executeCommand('reopenActiveEditorWith', 'default')),
vscode.commands.registerCommand('bbcode.togglePreview', () =>
vscode.commands.executeCommand('reopenActiveEditorWith',
vscode.window.activeTextEditor ? previewType : 'default'))
);
}
function deactivate() {}
module.exports = {
activate,
deactivate
};