Skip to content

Commit

Permalink
fix config 'emptyLineAction' default value
Browse files Browse the repository at this point in the history
validate enum settings on activate
'.emptyLineAction' fallback to default
update .gitignore add issues
update CHANGELOG 1.7.2
update package.json 1.7.2
  • Loading branch information
midnightsyntax committed Feb 19, 2019
1 parent 3a52449 commit 000482e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
out
node_modules
*.vsix
*.vsix
issues
25 changes: 17 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

# CHANGELOG

## 1.7.2
##### 2019-02-19

### Fixed

- Setting `.emptyLineAction` using wrong default value

---

## 1.7.1
##### 2019-01-15

Expand All @@ -18,19 +27,19 @@
##### 2019-01-13

### Added
- Setting `logFunctionName` has been added
- Setting `logString` has been added
- Setting `prefixFunctionName` has been added
- Setting `prefixString` has been added
- Setting `.logFunctionName` has been added
- Setting `.logString` has been added
- Setting `.prefixFunctionName` has been added
- Setting `.prefixString` has been added

### Changed
- Setting `setCursorOnNewLine` renamed to `configuration.moveToLine`
- Setting `cursorPositionNewLine` renamed to `configuration.moveToPosition`
- Setting `onEmptyLineAction` renamed to `configuration.emptyLineAction`
- Setting `.setCursorOnNewLine` renamed to `configuration.moveToLine`
- Setting `.cursorPositionNewLine` renamed to `configuration.moveToPosition`
- Setting `.onEmptyLineAction` renamed to `configuration.emptyLineAction`
- Various settings descriptions

### Removed
- Setting `wrapText` has been removed in favor of the new custom log settings
- Setting `.wrapText` has been removed in favor of the new custom log settings

## More custom log support
Get finer control over the inserted log string. It is now possible to set a custom function name for the default log command as well as the prefix command.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "git",
"url": "https://github.com/midnightsyntax/vscode-wrap-console-log"
},
"version": "1.7.1",
"version": "1.7.2",
"publisher": "midnightsyntax",
"icon": "images/icon.png",
"engines": {
Expand Down Expand Up @@ -54,7 +54,7 @@
"Replace empty"
],
"markdownDescription": "Defines the default text action when logging to an empty line. \n\n`Insert and push` will push the target line in the direction of the log command. \n\n`Replace empty` will replace the target line. No existing rows will be moved.",
"default": "Insert"
"default": "Insert and push"
},
"wrap-console-log.configuration.moveToLine": {
"type": "string",
Expand Down
30 changes: 27 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,31 @@

import * as vscode from 'vscode';
import { window, QuickPickItem, workspace } from 'vscode';
import * as path from 'path';
import * as fs from 'fs';

let currentEditor:vscode.TextEditor;
let currentContext:vscode.ExtensionContext;

export function activate(context: vscode.ExtensionContext) {

currentContext = context;
currentEditor = vscode.window.activeTextEditor;

var props = JSON.parse(fs.readFileSync(path.join(currentContext.extensionPath, 'package.json'), 'utf8')).contributes.configuration.properties;
Object.keys(props).forEach((prop, i) => {
let pName = prop.replace('wrap-console-log.','');
let pObj = props[prop];
let settingValue = getSetting(pName);
if (pObj) {
if (pObj.hasOwnProperty("enum")) {
console.log(`Checking enum config '${pName}'`);
let valueValid = pObj.enum.some(val => val == settingValue);
if (!valueValid) {
vscode.workspace.getConfiguration("wrap-console-log").update(pName, undefined);
console.log(`Invalid setting value! '${pName}' has been set to default value '${pObj.default}'`);
}
}
}
});
vscode.window.onDidChangeActiveTextEditor(editor => currentEditor = editor);

context.subscriptions.push(
Expand Down Expand Up @@ -212,14 +230,20 @@ function handle(target: Wrap, prefix?: boolean, input?: boolean, formatAs?: Form
nxtNonEmpty = (nxtLine.isEmptyOrWhitespace) ? wrap.doc.lineAt(getTargetLine(Wrap.Down)) : undefined;
}
if (wrap.lastLine == false && nxtLine.isEmptyOrWhitespace) {
if (onEmptyAction == "Insert and push") {
function defaultAction() {
e.insert(new vscode.Position(wrap.line, wrap.doc.lineAt(wrap.line).range.end.character), "\n".concat((nxtLineInd > wrap.ind ? nxtLineInd : wrap.ind), wrap.txt));
};
if (onEmptyAction == "Insert and push") {
defaultAction();
} else if (onEmptyAction == "Replace empty") {
if (nxtLine && (nxtNonEmpty.firstNonWhitespaceCharacterIndex > 0)) {
e.replace(new vscode.Position(nxtLine.lineNumber, 0), " ".repeat(nxtNonEmpty.firstNonWhitespaceCharacterIndex).concat(wrap.txt));
} else {
e.replace(new vscode.Position(nxtLine.lineNumber, 0), wrap.ind.concat(wrap.txt));
}
} else {
console.log(`Invalid config setting! Using 'emptyLineAction' default value`);
defaultAction();
}
} else {
e.insert(new vscode.Position(wrap.line, wrap.doc.lineAt(wrap.line).range.end.character),
Expand Down

0 comments on commit 000482e

Please sign in to comment.