mirror of
https://github.com/salexdv/bsl_console.git
synced 2024-11-24 08:33:29 +02:00
Команды для добавления и удаления комментариев
This commit is contained in:
parent
637559fc2d
commit
098f680038
@ -40,6 +40,26 @@ define(['vs/editor/editor.main'], function () {
|
||||
sendEvent('EVENT_FORMAT_CONSTRUCT', getFormatString());
|
||||
return null;
|
||||
}
|
||||
},
|
||||
comment_bsl: {
|
||||
label: 'Добавить комментарий',
|
||||
key: monaco.KeyMod.CtrlCmd | monaco.KeyCode.NUMPAD_DIVIDE,
|
||||
cmd: monaco.KeyMod.chord(monaco.KeyMod.CtrlCmd | monaco.KeyCode.NUMPAD_DIVIDE),
|
||||
order: 1.5,
|
||||
callback: function (ed) {
|
||||
addComment();
|
||||
return null;
|
||||
}
|
||||
},
|
||||
uncomment_bsl: {
|
||||
label: 'Удалить комментарий',
|
||||
key: monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.NUMPAD_DIVIDE,
|
||||
cmd: monaco.KeyMod.chord(monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.NUMPAD_DIVIDE),
|
||||
order: 1.6,
|
||||
callback: function (ed) {
|
||||
removeComment();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1525,4 +1525,88 @@ class bslHelper {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds min column in selected lines
|
||||
*
|
||||
* @param {Selection} current selection
|
||||
*
|
||||
* @returns {int} min column of selection
|
||||
*/
|
||||
getMinColumn(selection) {
|
||||
|
||||
let minColumn = 100000;
|
||||
|
||||
for (let line = selection.startLineNumber; line <= selection.endLineNumber; line++) {
|
||||
minColumn = Math.min(minColumn, this.model.getLineFirstNonWhitespaceColumn(line));
|
||||
}
|
||||
|
||||
return minColumn;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add comment for every selected lines
|
||||
*/
|
||||
addComment() {
|
||||
|
||||
let selection = editor.getSelection();
|
||||
let minColumn = this.getMinColumn(selection);
|
||||
|
||||
for (let line = selection.startLineNumber; line <= selection.endLineNumber; line++) {
|
||||
setText(
|
||||
'//' +
|
||||
this.model.getValueInRange({
|
||||
startLineNumber: line,
|
||||
startColumn: minColumn,
|
||||
endLineNumber: line,
|
||||
endColumn: this.model.getLineMaxColumn(line)
|
||||
}),
|
||||
{
|
||||
startLineNumber: line,
|
||||
startColumn: minColumn,
|
||||
endLineNumber: line,
|
||||
endColumn: this.model.getLineMaxColumn(line) + 2
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes comment from every selected lines
|
||||
*/
|
||||
removeComment() {
|
||||
|
||||
let selection = editor.getSelection();
|
||||
|
||||
for (let line = selection.startLineNumber; line <= selection.endLineNumber; line++) {
|
||||
|
||||
let firsColumn = this.model.getLineFirstNonWhitespaceColumn(line);
|
||||
let startChars = this.model.getValueInRange({
|
||||
startLineNumber: line,
|
||||
startColumn: firsColumn,
|
||||
endLineNumber: line,
|
||||
endColumn: Math.min(firsColumn + 2, this.model.getLineMaxColumn(line))
|
||||
});
|
||||
|
||||
if (startChars == '//') {
|
||||
setText(
|
||||
this.model.getValueInRange({
|
||||
startLineNumber: line,
|
||||
startColumn: firsColumn + 2,
|
||||
endLineNumber: line,
|
||||
endColumn: this.model.getLineMaxColumn(line)
|
||||
}),
|
||||
{
|
||||
startLineNumber: line,
|
||||
startColumn: firsColumn,
|
||||
endLineNumber: line,
|
||||
endColumn: this.model.getLineMaxColumn(line)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -83,6 +83,20 @@ define(['bslGlobals', 'bslMetadata', 'snippets', 'bsl_language', 'vs/editor/edit
|
||||
engLang = !engLang;
|
||||
}
|
||||
|
||||
addComment = function () {
|
||||
|
||||
let bsl = new bslHelper(editor.getModel(), editor.getPosition());
|
||||
bsl.addComment();
|
||||
|
||||
}
|
||||
|
||||
removeComment = function () {
|
||||
|
||||
let bsl = new bslHelper(editor.getModel(), editor.getPosition());
|
||||
bsl.removeComment();
|
||||
|
||||
}
|
||||
|
||||
// Register a new language
|
||||
monaco.languages.register({ id: language.id });
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user