Skip to content
This repository was archived by the owner on May 27, 2021. It is now read-only.

Commit 50d6a84

Browse files
committed
fix vscode 1.29.0's breaking feature: eol=auto
1 parent 1fc815e commit 50d6a84

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/extension.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ class MarkdownTocTools {
126126
let tocRange = this.getTocRange();
127127
this.updateOptions(tocRange);
128128
let headerList = this.getHeaderList();
129-
129+
130130
window.activeTextEditor.edit(function(editBuilder) {
131-
headerList.forEach(element => {
131+
headerList.forEach(element => {
132132
let newHeader = element.header + " " + element.orderedList + " " + element.baseTitle
133133
editBuilder.replace(element.range, newHeader);
134134
});
@@ -203,7 +203,7 @@ class MarkdownTocTools {
203203
let optionsText = window.activeTextEditor.document.lineAt(tocRange.start.line).text;
204204
let options = optionsText.match(REGEXP_TOC_CONFIG);
205205
if (options == null) return;
206-
206+
207207
options.forEach(element => {
208208
let pair = REGEXP_TOC_CONFIG_ITEM.exec(element)
209209
let key = pair[1].toLocaleLowerCase();
@@ -265,9 +265,12 @@ class MarkdownTocTools {
265265

266266
private createToc(editBuilder : TextEditorEdit, headerList : any[], insertPosition : Position) {
267267
let lineEnding = <string> workspace.getConfiguration("files").get("eol");
268+
if (lineEnding === "auto") {
269+
lineEnding = "\n";
270+
}
268271
let tabSize = <number> workspace.getConfiguration("[markdown]")["editor.tabSize"];
269272
let insertSpaces = <boolean> workspace.getConfiguration("[markdown]")["editor.insertSpaces"];
270-
273+
271274
if(tabSize === undefined || tabSize === null) {
272275
tabSize = <number> workspace.getConfiguration("editor").get("tabSize");
273276
}
@@ -278,7 +281,7 @@ class MarkdownTocTools {
278281
let tab = '\t';
279282
if (insertSpaces && tabSize > 0) {
280283
tab = " ".repeat(tabSize);
281-
}
284+
}
282285

283286
let optionsText = [];
284287
optionsText.push('<!-- TOC ');
@@ -302,7 +305,7 @@ class MarkdownTocTools {
302305
minDepth = Math.min(element.depth, minDepth);
303306
});
304307
let startDepth = Math.max(minDepth , this.options.DEPTH_FROM);
305-
308+
306309
headerList.forEach(element => {
307310
if (element.depth <= this.options.DEPTH_TO) {
308311
let length = element.depth - startDepth;
@@ -312,7 +315,7 @@ class MarkdownTocTools {
312315
waitResetList[index] = false;
313316
}
314317
}
315-
318+
316319
let row = [
317320
tab.repeat(length),
318321
this.options.ORDERED_LIST ? (++indicesOfDepth[length] + '. ') : '- ',
@@ -376,7 +379,7 @@ class MarkdownTocTools {
376379
} else {
377380
hashMap[title] += 1;
378381
}
379-
382+
380383
let hash = this.getHash(title, this.options.ANCHOR_MODE, hashMap[title]);
381384
headerList.push({
382385
line : index,

0 commit comments

Comments
 (0)