-
Notifications
You must be signed in to change notification settings - Fork 1
/
extension.js
73 lines (60 loc) · 1.87 KB
/
extension.js
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
61
62
63
64
65
66
67
68
69
70
71
72
73
const { log } = require('console');
const vscode = require('vscode');
function Extension() {
let file1;
let file2;
/**
* @param {vscode.Uri} uri
*/
this.selectForCompare = function (uri) {
//set file 1
file1 = uri
//setContext compareEnabled = true
vscode.commands.executeCommand('setContext', 'select-compare-tabs.compareEnabled', true);
}
/**
* @param {vscode.Uri} uri
*/
this.compareWithSelected = function (uri) {
//set file 2
file2 = uri
//open diff editor
vscode.commands.executeCommand('vscode.diff', file1, file2);
//setContext compareEnabled = false
vscode.commands.executeCommand('setContext', 'select-compare-tabs.compareEnabled', false);
}
this.swapFiles = function () {
//get visible editors in diff panel
let selectedEditors = vscode.window.visibleTextEditors;
//switch files and set
if(typeof selectedEditors[2] !=='undefined'){
file1 = selectedEditors[2].document.uri;
file2 = selectedEditors[1].document.uri;
} else {
file1 = selectedEditors[1].document.uri;
file2 = selectedEditors[0].document.uri;
}
//close diff editor
vscode.commands.executeCommand('workbench.action.closeActiveEditor');
//open new diff editor
vscode.commands.executeCommand('vscode.diff', file1, file2);
}
}
function activate(context) {
//INIT EXTENSION
let ext = new Extension();
//COMMANDS
context.subscriptions.push(vscode.commands.registerCommand('select-compare-tabs.selectForCompare', function (event) {
//selectForCompare
ext.selectForCompare(event);
}));
context.subscriptions.push(vscode.commands.registerCommand('select-compare-tabs.compareWithSelected', function (event) {
//compareWithSelected
ext.compareWithSelected(event);
}));
context.subscriptions.push(vscode.commands.registerCommand('select-compare-tabs.swapFiles', function () {
//swapFiles
ext.swapFiles();
}));
}
exports.activate = activate;