Updating a TOC with style bitbucket.org and Insert Anchor enabled inserts one additional empty line per update.
It seems like there's code that tries to prevent this, but has some bugs:
It's always executed, not only in the bitbucket.org style
When checking if the additional empty line is there, it checks the line of the anchor (which of course is never empty)
It compares the line with this.configManager.options.lineEnding when it should compare it with an empty string
It would try to remove the empty line in the wrong position (before the anchor instead of after the anchor)
I managed to fix the code directly in the installed AutoMarkdownToc.js, but since that's practically identical to the typescript source, I think sharing it here may help:
deleteAnchors(editBuilder) {
let editor = vscode_1.window.activeTextEditor;
if (editor != undefined) {
let doc = editor.document;
for (let index = 0; index < doc.lineCount; index++) {
let lineText = doc.lineAt(index).text;
if (lineText.match(RegexStrings_1.RegexStrings.Instance.REGEXP_MARKDOWN_ANCHOR) == null) {
continue;
}
let startPosition = new vscode_1.Position(index, 0);
let endPosition = new vscode_1.Position(index + 1, 0);
// To ensure the anchor will not insert an extra empty line
if (this.configManager.options.ANCHOR_MODE.value == AnchorMode_1.AnchorMode.bitbucket) {
if ((index + 1) < doc.lineCount && doc.lineAt(index + 1).text == "") {
endPosition = new vscode_1.Position(index + 2, 0);
}
}
let range = new vscode_1.Range(startPosition, endPosition);
editBuilder.delete(range);
}
}
}
Updating a TOC with style
bitbucket.org
andInsert Anchor
enabled inserts one additional empty line per update.It seems like there's code that tries to prevent this, but has some bugs:
bitbucket.org
stylethis.configManager.options.lineEnding
when it should compare it with an empty stringI managed to fix the code directly in the installed
AutoMarkdownToc.js
, but since that's practically identical to the typescript source, I think sharing it here may help: