mirror of
https://github.com/We-Dont-Byte/Mind_Reader.git
synced 2024-11-15 03:35:59 +00:00
added new function
added fetchNumberOfSelectedLines and getNumberOfSelectedLines
This commit is contained in:
parent
16869aa5b6
commit
5d3dc7acea
@ -16,6 +16,10 @@ export const textCommands: CommandEntry[] = [
|
||||
name: 'mind-reader.getLeadingSpaces',
|
||||
callback: getLeadingSpaces,
|
||||
},
|
||||
{
|
||||
name: 'mind-reader.getNumberOfSelectedLines',
|
||||
callback: getNumberOfSelectedLines,
|
||||
},
|
||||
{
|
||||
name: 'mind-reader.runLineContext',
|
||||
callback: runLineContext,
|
||||
@ -26,6 +30,19 @@ export const textCommands: CommandEntry[] = [
|
||||
}
|
||||
];
|
||||
|
||||
/* Helper Function
|
||||
* This function returns the number of selected lines in the active text editor window
|
||||
*/
|
||||
function fetchNumberOfSelectedLines(editor: vscode.TextEditor | undefined): number {
|
||||
let numberOfSelectedLines: number = 0;
|
||||
|
||||
if (editor) {
|
||||
numberOfSelectedLines = editor.selections.reduce((prev, curr) => prev + (curr.end.line - curr.start.line), 1);
|
||||
}
|
||||
|
||||
return numberOfSelectedLines;
|
||||
}
|
||||
|
||||
/* Helper Function
|
||||
* This function returns the line number of the active text editor window
|
||||
*/
|
||||
@ -40,7 +57,28 @@ function fetchTextLine(editor: any): string {
|
||||
return editor.document.lineAt(fetchLineNumber(editor) - 1);
|
||||
}
|
||||
|
||||
// Function that outputs the current line number the cursor is on
|
||||
/** Function
|
||||
* Function to return the number of selected (highlighted) lines
|
||||
* Changes output to 'Line' for 1 line and 'Lines' for all other instances
|
||||
*/
|
||||
function getNumberOfSelectedLines(): void {
|
||||
const editor: any = vscode.window.activeTextEditor;
|
||||
|
||||
if (editor) {
|
||||
const numberOfSelectedLines: number = fetchNumberOfSelectedLines(editor);
|
||||
|
||||
(numberOfSelectedLines !== 1)
|
||||
? vscode.window.showInformationMessage(`${numberOfSelectedLines.toString()} Lines Selected`)
|
||||
: vscode.window.showInformationMessage(`${numberOfSelectedLines.toString()} Line Selected`);
|
||||
}
|
||||
else {
|
||||
vscode.window.showErrorMessage('No document currently active');
|
||||
}
|
||||
}
|
||||
|
||||
/** Function
|
||||
* Outputs the current line number the cursor is on
|
||||
*/
|
||||
function getLineNumber(): void {
|
||||
const editor: any = vscode.window.activeTextEditor;
|
||||
|
||||
@ -54,6 +92,9 @@ function getLineNumber(): void {
|
||||
}
|
||||
}
|
||||
|
||||
/** Function
|
||||
* Used to get the number of indents on a line
|
||||
*/
|
||||
function getIndent(): void {
|
||||
const editor: any = vscode.window.activeTextEditor;
|
||||
|
||||
@ -72,7 +113,9 @@ function getIndent(): void {
|
||||
};
|
||||
const i: number = pl.Lexer.getIndent(textLine.text, tabFmt);
|
||||
|
||||
vscode.window.showInformationMessage(`Line ${lineNum.toString()}: ${i.toString()} indents`);
|
||||
(i !== 1)
|
||||
? vscode.window.showInformationMessage(`Line ${lineNum.toString()}: ${i.toString()} indents`)
|
||||
: vscode.window.showInformationMessage(`Line ${lineNum.toString()}: ${i.toString()} indent`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -114,14 +157,14 @@ function getLeadingSpaces(): void {
|
||||
* default: false
|
||||
*/
|
||||
const calculateLeadingSpaces: boolean = false; // change boolean value to change method
|
||||
const numSpaces: number = (calculateLeadingSpaces) ?
|
||||
pl.Lexer.getLeadingSpacesByArithmetic(textLine) :
|
||||
pl.Lexer.getLeadingSpacesByIndex(textLine);
|
||||
const numSpaces: number = (calculateLeadingSpaces)
|
||||
? pl.Lexer.getLeadingSpacesByArithmetic(textLine)
|
||||
: pl.Lexer.getLeadingSpacesByIndex(textLine);
|
||||
|
||||
/* Ternary operator to change the tense of 'space' to 'spaces' for the output if numSpaces is 0 or greater than 1 */
|
||||
(numSpaces !== 1) ?
|
||||
vscode.window.showInformationMessage(`Line ${lineNum.toString()}: ${numSpaces.toString()} spaces`):
|
||||
vscode.window.showInformationMessage(`Line ${lineNum.toString()}: ${numSpaces.toString()} space`);
|
||||
(numSpaces !== 1)
|
||||
? vscode.window.showInformationMessage(`Line ${lineNum.toString()}: ${numSpaces.toString()} spaces`)
|
||||
: vscode.window.showInformationMessage(`Line ${lineNum.toString()}: ${numSpaces.toString()} space`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
Loading…
Reference in New Issue
Block a user