Skip to content

Commit a4a5812

Browse files
authored
Merge pull request #24 from MaxBec/development
v2.0.0 Beta2
2 parents 15683f1 + 4ecddd1 commit a4a5812

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

out/extension.js

Lines changed: 14 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/extension.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
],
102102
"enumDescriptions": [
103103
"Formats the files in a column-style. E.g. in an items file each item is one line separated by tabs.",
104-
"Formats the files in a multiline-style. E.g. in an items file each part of the channel configuration is written in a new line."
104+
"Formats the files in a column-style with each hannel parameter in a new line. E.g. in an items file each part of the channel configuration is written in a new line.",
105105
"Formats the files in a multiline-style. E.g. in an items file each part of an item is written in a new line."
106106
]
107107
},
@@ -207,7 +207,7 @@
207207
"@types/glob": "^7.1.1",
208208
"@types/mocha": "^5.2.6",
209209
"@types/node": "^10.17.21",
210-
"@types/vscode": "^1.44.0",
210+
"@types/vscode": "^1.40.0",
211211
"glob": "^7.1.6",
212212
"mocha": "^6.2.3",
213213
"tslint": "^5.20.1",

src/extension.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const REGEX_ITEM_ICON = /<.+?>/;
2525
const REGEX_ITEM_GROUP = /\(.+?\)/;
2626
const REGEX_ITEM_TAG = /\[\s*(\".+?\")\s*(,\s*\".+?\"\s*)*\]/;
2727
const REGEX_ITEM_CHANNEL_START = /\{\s*(\w*=".*"?,?\s*)+\}?/;
28-
const REGEX_ITEM_CHANNEL_END = /\S*[\},]/;
28+
const REGEX_ITEM_CHANNEL_END = /.*[\},]/;
2929

3030
const REGEX_SITEMAP_ELEMENTS = /\b(Frame|Default|Text|Group|Switch|Selection|Setpoint|Slider|Colorpicker|Webview|Mapview|Image|Video|Chart)\b/g;
3131

@@ -289,7 +289,7 @@ function formatItemFile(range?: vscode.Range): vscode.TextEdit[] {
289289
} else {
290290
let itemChannelRange = doc.getWordRangeAtPosition(newPos, REGEX_ITEM_CHANNEL_END);
291291
if (itemChannelRange && itemChannelRange.isSingleLine) {
292-
itemChannel += doc.getText(itemChannelRange);
292+
itemChannel += doc.getText(itemChannelRange).trimLeft();
293293
if (itemChannel.endsWith("}")) {
294294
channelPending = false;
295295
}
@@ -302,7 +302,7 @@ function formatItemFile(range?: vscode.Range): vscode.TextEdit[] {
302302

303303
// Discover comment at end of line
304304
let itemCommentRange = doc.getWordRangeAtPosition(newPos, REGEX_EOL_COMMENT);
305-
if (itemCommentRange && itemCommentRange.isSingleLine) {
305+
if (itemCommentRange && itemCommentRange.isSingleLine && itemCommentRange.start.character >= newPos.character) {
306306
itemComment = doc.getText(itemCommentRange);
307307
newPos = newPos.with(newPos.line, newPos.character + itemComment.length);
308308
newPos = newPos.with(newPos.line, newPos.character + utils.countWhitespace(doc, newPos));
@@ -379,13 +379,24 @@ function formatItem(item: Item): string {
379379

380380
if (formatStyle === "ChannelColumn") {
381381
let tabs = "";
382+
let spaces = "";
382383
let tabIndent = highestTypeLength + highestNameLength + highestLabelLength + highestIconLength + highestGroupLength + highestTagLength;
383384

384385
for (let i = 0; i < tabIndent; i++) {
385386
tabs = tabs + "\t";
386387
}
387-
tabs = ",\n" + tabs + " ";
388-
item.channel = item.channel.replace(/,\s*/g, tabs);
388+
389+
var identResult = item.channel.match(/.*\="/g);
390+
let identCount = 0;
391+
if (identResult) {
392+
identCount = identResult[0].length;
393+
for (let e = 0; e < identCount; e++) {
394+
spaces = spaces + " ";
395+
}
396+
}
397+
398+
item.channel = item.channel.replace(/",\s*/g, '",\n' + tabs + " ");
399+
item.channel = item.channel.replace(/([^"]),\s*/g, "$1,\n" + tabs + spaces);
389400
}
390401

391402
// Build the formatted item and return it

0 commit comments

Comments
 (0)