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

fix vscode 1.29.0's breaking feature: eol=auto #66

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/extension.ts
Expand Up @@ -126,9 +126,9 @@ class MarkdownTocTools {
let tocRange = this.getTocRange();
this.updateOptions(tocRange);
let headerList = this.getHeaderList();

window.activeTextEditor.edit(function(editBuilder) {
headerList.forEach(element => {
headerList.forEach(element => {
let newHeader = element.header + " " + element.orderedList + " " + element.baseTitle
editBuilder.replace(element.range, newHeader);
});
Expand Down Expand Up @@ -203,7 +203,7 @@ class MarkdownTocTools {
let optionsText = window.activeTextEditor.document.lineAt(tocRange.start.line).text;
let options = optionsText.match(REGEXP_TOC_CONFIG);
if (options == null) return;

options.forEach(element => {
let pair = REGEXP_TOC_CONFIG_ITEM.exec(element)
let key = pair[1].toLocaleLowerCase();
Expand Down Expand Up @@ -265,9 +265,12 @@ class MarkdownTocTools {

private createToc(editBuilder : TextEditorEdit, headerList : any[], insertPosition : Position) {
let lineEnding = <string> workspace.getConfiguration("files").get("eol");
if (lineEnding === "auto") {
lineEnding = "\n";
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should come from the current document 🤔

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, should be better taken either from current document, or probably vscode provides some API to resolve auto to os-specific value.

}
let tabSize = <number> workspace.getConfiguration("[markdown]")["editor.tabSize"];
let insertSpaces = <boolean> workspace.getConfiguration("[markdown]")["editor.insertSpaces"];

if(tabSize === undefined || tabSize === null) {
tabSize = <number> workspace.getConfiguration("editor").get("tabSize");
}
Expand All @@ -278,7 +281,7 @@ class MarkdownTocTools {
let tab = '\t';
if (insertSpaces && tabSize > 0) {
tab = " ".repeat(tabSize);
}
}

let optionsText = [];
optionsText.push('<!-- TOC ');
Expand All @@ -302,7 +305,7 @@ class MarkdownTocTools {
minDepth = Math.min(element.depth, minDepth);
});
let startDepth = Math.max(minDepth , this.options.DEPTH_FROM);

headerList.forEach(element => {
if (element.depth <= this.options.DEPTH_TO) {
let length = element.depth - startDepth;
Expand All @@ -312,7 +315,7 @@ class MarkdownTocTools {
waitResetList[index] = false;
}
}

let row = [
tab.repeat(length),
this.options.ORDERED_LIST ? (++indicesOfDepth[length] + '. ') : '- ',
Expand Down Expand Up @@ -376,7 +379,7 @@ class MarkdownTocTools {
} else {
hashMap[title] += 1;
}

let hash = this.getHash(title, this.options.ANCHOR_MODE, hashMap[title]);
headerList.push({
line : index,
Expand Down