Repository navigation
Expand file tree
/
Copy pathextension.js
More file actions
46 lines (35 loc) · 1.34 KB
/
Copy pathextension.js
File metadata and controls
46 lines (35 loc) · 1.34 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
const vscode = require('vscode')
function colonize (option) {
var editor = vscode.window.activeTextEditor
if (!editor) return
vscode.commands.executeCommand('acceptSelectedSuggestion').then(() => {
var lineIndex = editor.selection.active.line
var lineObject = editor.document.lineAt(lineIndex)
var lineLength = lineObject.text.length
if (lineObject.text.charAt(lineLength - 1) !== ';' && !lineObject.isEmptyOrWhitespace) {
var insertionSuccess = editor.edit((editBuilder) => {
editBuilder.insert(new vscode.Position(lineIndex, lineLength), ';')
})
if (!insertionSuccess) return
}
if (option === 'hold') return
option === 'endline'
? vscode.commands.executeCommand('cursorEnd')
: vscode.commands.executeCommand('editor.action.insertLineAfter')
})
}
function activate (context) {
var endLineDisposable = vscode.commands.registerCommand('colonize.endline', () => {
colonize('endline')
})
var holdDisposable = vscode.commands.registerCommand('colonize.hold', () => {
colonize('hold')
})
var newLineDisposable = vscode.commands.registerCommand('colonize.newline', () => {
colonize('newline')
})
context.subscriptions.push(endLineDisposable)
context.subscriptions.push(newLineDisposable)
context.subscriptions.push(holdDisposable)
}
exports.activate = activate