feat: Add current column to the details section (#60)

* Add current column

* Update package.json

* Fix bugs!!!
This commit is contained in:
Frangu Vlad 2018-05-01 16:16:59 +03:00 committed by Crawl
parent 3906cde96a
commit 4fd0d2eb5e
2 changed files with 14 additions and 7 deletions

View file

@ -63,12 +63,12 @@
"discord.detailsEditing": {
"type": "string",
"default": "Editing {filename}",
"description": "Custom string for the details section of the rich presence\n\t- '{null}' will be replaced with an empty space.\n\t- '{filename}' will be replaced with the current file name.\n\t- '{dirname}' will get replaced with the folder name that has the current file.\n\t- '{fulldirname}' will get replaced with the full directory name without the current file name.\n\t- '{workspace}' will be replaced with the current workspace name, if any.\n\t- '{currentline}' will get replaced with the current line number.\n\t- '{totallines}' will get replaced with the total line number.\n\t- '{filesize}' will get replaced with the current file's size."
"description": "Custom string for the details section of the rich presence\n\t- '{null}' will be replaced with an empty space.\n\t- '{filename}' will be replaced with the current file name.\n\t- '{dirname}' will get replaced with the folder name that has the current file.\n\t- '{fulldirname}' will get replaced with the full directory name without the current file name.\n\t- '{workspace}' will be replaced with the current workspace name, if any.\n\t- '{currentcolumn}' will get replaced with the current column of the current line.\n\t- '{currentline}' will get replaced with the current line number.\n\t- '{totallines}' will get replaced with the total line number.\n\t- '{filesize}' will get replaced with the current file's size."
},
"discord.detailsDebugging": {
"type": "string",
"default": "Editing {filename}",
"description": "Custom string for the details section of the rich presence when debugging\n\t- '{null}' will be replaced with an empty space.\n\t- '{filename}' will be replaced with the current file name.\n\t- '{dirname}' will get replaced with the folder name that has the current file.\n\t- '{fulldirname}' will get replaced with the full directory name without the current file name.\n\t- '{workspace}' will be replaced with the current workspace name, if any.\n\t- '{currentline}' will get replaced with the current line number.\n\t- '{totallines}' will get replaced with the total line number.\n\t- '{filesize}' will get replaced with the current file's size."
"description": "Custom string for the details section of the rich presence when debugging\n\t- '{null}' will be replaced with an empty space.\n\t- '{filename}' will be replaced with the current file name.\n\t- '{dirname}' will get replaced with the folder name that has the current file.\n\t- '{fulldirname}' will get replaced with the full directory name without the current file name.\n\t- '{workspace}' will be replaced with the current workspace name, if any.\n\t- '{currentcolumn}' will get replaced with the current column of the current line.\n\t- '{currentline}' will get replaced with the current line number.\n\t- '{totallines}' will get replaced with the total line number.\n\t- '{filesize}' will get replaced with the current file's size."
},
"discord.detailsIdle": {
"type": "string",
@ -78,12 +78,12 @@
"discord.lowerDetailsEditing": {
"type": "string",
"default": "Workspace: {workspace}",
"description": "Custom string for the state section of the rich presence\n\t- '{null}' will be replaced with an empty space.\n\t- '{filename}' will be replaced with the current file name.\n\t- '{dirname}' will get replaced with the folder name that has the current file.\n\t- '{fulldirname}' will get replaced with the full directory name without the current file name.\n\t- '{workspace}' will be replaced with the current workspace name, if any.\n\t- '{currentline}' will get replaced with the current line number.\n\t- '{totallines}' will get replaced with the total line number.\n\t- '{filesize}' will get replaced with the current file's size."
"description": "Custom string for the state section of the rich presence\n\t- '{null}' will be replaced with an empty space.\n\t- '{filename}' will be replaced with the current file name.\n\t- '{dirname}' will get replaced with the folder name that has the current file.\n\t- '{fulldirname}' will get replaced with the full directory name without the current file name.\n\t- '{workspace}' will be replaced with the current workspace name, if any.\n\t- '{currentcolumn}' will get replaced with the current column of the current line.\n\t- '{currentline}' will get replaced with the current line number.\n\t- '{totallines}' will get replaced with the total line number.\n\t- '{filesize}' will get replaced with the current file's size."
},
"discord.lowerDetailsDebugging": {
"type": "string",
"default": "Debugging: {workspace}",
"description": "Custom string for the state section of the rich presence when debugging\n\t- '{null}' will be replaced with an empty space.\n\t- '{filename}' will be replaced with the current file name.\n\t- '{dirname}' will get replaced with the folder name that has the current file.\n\t- '{fulldirname}' will get replaced with the full directory name without the current file name..\n\t- '{workspace}' will be replaced with the current workspace name, if any.\n\t- '{currentline}' will get replaced with the current line number.\n\t- '{totallines}' will get replaced with the total line number.\n\t- '{filesize}' will get replaced with the current file's size."
"description": "Custom string for the state section of the rich presence when debugging\n\t- '{null}' will be replaced with an empty space.\n\t- '{filename}' will be replaced with the current file name.\n\t- '{dirname}' will get replaced with the folder name that has the current file.\n\t- '{fulldirname}' will get replaced with the full directory name without the current file name..\n\t- '{workspace}' will be replaced with the current workspace name, if any.\n\t- '{currentcolumn}' will get replaced with the current column of the current line.\n\t- '{currentline}' will get replaced with the current line number.\n\t- '{totallines}' will get replaced with the total line number.\n\t- '{filesize}' will get replaced with the current file's size."
},
"discord.lowerDetailsIdle": {
"type": "string",

View file

@ -21,6 +21,7 @@ interface FileDetail {
size: string | null;
totalLines: string | null;
currentLine: string | null;
currentColumn: string | null;
}
const knownExtentions: { [x: string]: { image: string } } = lang.knownExtentions;
@ -278,8 +279,8 @@ function setActivity(workspaceElapsedTime: boolean = false): void {
}
function generateDetails(debugging, editing, idling): string {
let string: string = config.get(idling);
const emptySpaces = '\u200b\u200b';
let string: string = config.get(idling).replace('{null}', emptySpaces);
const fileName: string = window.activeTextEditor ? basename(window.activeTextEditor.document.fileName) : null;
let dirName: string = null;
@ -305,7 +306,7 @@ function generateDetails(debugging, editing, idling): string {
if (window.activeTextEditor) {
if (debug.activeDebugSession) {
let rawString = config.get(debugging);
const { totalLines, size, currentLine } = getFileDetails(rawString);
const { totalLines, size, currentLine, currentColumn } = getFileDetails(rawString);
rawString = rawString
.replace('{null}', emptySpaces)
.replace('{filename}', fileName)
@ -319,10 +320,11 @@ function generateDetails(debugging, editing, idling): string {
if (totalLines) rawString = rawString.replace('{totallines}', totalLines);
if (size) rawString = rawString.replace('{filesize}', size);
if (currentLine) rawString = rawString.replace('{currentline}', currentLine);
if (currentColumn) rawString = rawString.replace('{currentcolumn}', currentColumn);
string = rawString;
} else {
let rawString = config.get(editing);
const { totalLines, size, currentLine } = getFileDetails(rawString);
const { totalLines, size, currentLine, currentColumn } = getFileDetails(rawString);
rawString = rawString
.replace('{null}', emptySpaces)
.replace('{filename}', fileName)
@ -336,6 +338,7 @@ function generateDetails(debugging, editing, idling): string {
if (totalLines) rawString = rawString.replace('{totallines}', totalLines);
if (size) rawString = rawString.replace('{filesize}', size);
if (currentLine) rawString = rawString.replace('{currentline}', currentLine);
if (currentColumn) rawString = rawString.replace('{currentcolumn}', currentColumn);
string = rawString;
}
}
@ -348,6 +351,7 @@ function getFileDetails(rawString): FileDetail {
size: null,
totalLines: null,
currentLine: null,
currentColumn: null,
};
if (!rawString) return obj;
if (rawString.includes('{totallines}')) {
@ -356,6 +360,9 @@ function getFileDetails(rawString): FileDetail {
if (rawString.includes('{currentline}')) {
obj.currentLine = (window.activeTextEditor.selection.active.line + 1).toLocaleString();
}
if (rawString.includes('{currentcolumn}')) {
obj.currentColumn = (window.activeTextEditor.selection.active.character + 1).toLocaleString();
}
if (rawString.includes('{filesize}')) {
const sizes = ['bytes', 'kb', 'mb', 'gb', 'tb'];
let currentDivision = 0;