프로그램을 하다 보면 블럭을 설정해야 되는 경우가 있습니다.
그런 경우 유용한 프로그램 입니다.
전 : 또는 = 정렬이 필요한 경우가 있는데 유용하게 사용하고 있습니다.
1) 마우스로 블럭을 설정 합니다.
2) F1 키를 클릭 후 Align Text Tokens 를 찾습니다.
3) 어떤 기호를 정렬할지 입력해주고 엔터를 칩니다.
그다음 블럭설정등 하여 한꺼번에 수정 해야 되는 작업을 하면 됩니다.
가변길이 폰트는 비뚤빼둘해서 이런것에는 좋지 않아서 보기 좋지 않아도 고정길이 폰트를 사용하는 편입니다.
아 코딩용 폰트는 좀 잘해서 고정길이로 만들어 주면 안되나... 코딩용이라고 가변길이로 만들어 간간히 삐둘빼둘되어 한칸더 밀어야 되나?? 그런 경우가 있음.!!
아래 프로그램을 수정해 주면 됩니다.
C:\Users\<본인계정>\.vscode\extensions\sergelamikhov.aligntokens-1.0.11\out\extension.js
굴림체, 바탕체 선택 하시면 됩니다. 고정길이 폰트로 딱딱하고 이쁘지 않은 단점이 있지만 줄이 잘 맞기 때문에 선문자 깨지지 않고 좋습니다.
그리고 한글 변수 사용하면 배열이나 일부 블럭 단위로 복사할때 무척 유용합니다.
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.activate = void 0;
const vscode = require("vscode");
function activate(context) {
let disposable = vscode.commands.registerTextEditorCommand('extension.alignTokens', alignTokens);
context.subscriptions.push(disposable);
}
exports.activate = activate;
async function alignTokens(textEditor, edit, ...args) {
vscode.window.showInputBox({
prompt: 'Provide text to align:',
value: '='
}).then(token => {
if (token !== undefined && token.length > 0) {
let selections = textEditor.selections;
// If there is no selection, do the job for the whole file
if (selections.length === 1 && selections[0].start.line === selections[0].end.line) {
textEditor.selection = new vscode.Selection(0, 0, textEditor.document.lineCount - 1, 0);
}
let farthestPosition = findFarthestPosition(selections, token);
if (farthestPosition !== -1) {
alignAccordingToFarthestPosition(selections, token, farthestPosition);
}
}
});
// 한글 문자의 너비를 계산하는 함수
function getVisualWidth(text) {
let width = 0;
for (let char of text) {
// 한 // 한글 유니코드 범위: AC00–D7AF
if (/[\uAC00-\uD7AF]/.test(char)) {
width += 2; // 한글은 2칸으로 계산
} else {
width += 1; // ASCII 등은 1칸
}
}
return width;
}
function findFarthestPosition(selections, token) {
let farthestPosition = -1;
for (let selection of selections) {
for (let lineNo = selection.start.line; lineNo <= selection.end.line; ++lineNo) {
let lineText = textEditor.document.lineAt(lineNo).text;
let foundAt = lineText.indexOf(token);
if (foundAt !== -1) {
// 토큰 앞부분의 시각적 너비 계산
let textBeforeToken = lineText.substring(0, foundAt);
let visualWidth = getVisualWidth(textBeforeToken);
if (visualWidth > farthestPosition) {
farthestPosition = visualWidth;
}
}
}
}
return farthestPosition;
}
function alignAccordingToFarthestPosition(selections, token, farthestPosition) {
textEditor.edit(editBuilder => {
for (let selection of selections) {
for (let lineNo = selection.start.line; lineNo <= selection.end.line; ++lineNo) {
let line = textEditor.document.lineAt(lineNo);
let lineText = line.text;
let foundAt = lineText.indexOf(token);
if (foundAt !== -1) {
let textBeforeToken = lineText.substring(0, foundAt);
let visualWidth = getVisualWidth(textBeforeToken);
let spacesNeeded = farthestPosition - visualWidth;
if (spacesNeeded > 0) {
lineText = textBeforeToken +
' '.repeat(spacesNeeded) +
lineText.substring(foundAt);
editBuilder.replace(line.range, lineText);
}
}
}
}
});
}
}