Skip to content

Commit

Permalink
Merge pull request #107 from kasecato/#106/strange_indent
Browse files Browse the repository at this point in the history
Fixed #106 strange indent on delimiterd comment and tab
  • Loading branch information
kasecato authored Jul 27, 2020
2 parents bad920a + d6590ee commit 292e837
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* bug fix - ctrl-enter (insert line below, insert line above) in middle of line not adding `///`. See [#98](https://github.com/kasecato/vscode-docomment/issues/98).
* bug fix - Not working activateOnEnter. See [#104](https://github.com/kasecato/vscode-docomment/issues/104).
* bug fix - Strange tab indent. See [#106](https://github.com/kasecato/vscode-docomment/issues/106).

## 0.1.15 (July 26, 2020)

Expand Down
4 changes: 2 additions & 2 deletions src/Domain/Lang/DocommentDomainCSharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class DocommentDomainCSharp extends DocommentDomain {
if (codeType === CodeType.Comment) {
const indentBaseLine: string = this._vsCodeApi.ReadLineAtCurrent();
const indent: string = StringUtil.GetIndent(code, indentBaseLine, this._config.insertSpaces, this._config.detectIdentation);
const indentLen: number = StringUtil.GetIndentLen(indent, this._config.insertSpaces, this._config.detectIdentation);
const indentLen: number = StringUtil.GetIndentLen(indent, this._config.syntax, this._config.insertSpaces, this._config.detectIdentation);
const lineOffset = this._isInsertDocCommentLineAbove ? 0 : 1;
const charOffset = this._isInsertDocCommentLineAbove ? 0 : -1;
const insertPosition: Position = this._vsCodeApi.GetPosition(position.line + lineOffset, indentLen + charOffset);
Expand All @@ -226,7 +226,7 @@ export class DocommentDomainCSharp extends DocommentDomain {
const curPosition = this._vsCodeApi.GetActivePosition();
const indentBaseLine: string = this._vsCodeApi.ReadLineAtCurrent();
const indent: string = StringUtil.GetIndent(code, indentBaseLine, this._config.insertSpaces, this._config.detectIdentation);
const indentLen: number = StringUtil.GetIndentLen(indent, this._config.insertSpaces, this._config.detectIdentation);
const indentLen: number = StringUtil.GetIndentLen(indent, this._config.syntax, this._config.insertSpaces, this._config.detectIdentation);
const line = curPosition.line + SyntacticAnalysisCSharp.GetLineOffset(this._config.syntax, codeType);
const lineOffset = this._isInsertDocCommentLineAbove ? -1 : 0;
const character = indentLen - 1 + docomment.length;
Expand Down
7 changes: 5 additions & 2 deletions src/Utility/StringUtil.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { CommentSyntax } from "../Entity/Config/Contributes/Configuration";

export class StringUtil {

/*-------------------------------------------------------------------------
Expand Down Expand Up @@ -50,7 +52,7 @@ export class StringUtil {
}
}

public static GetIndentLen(indent: string, insertSpaces: boolean, detectIdentation: boolean): number {
public static GetIndentLen(indent: string, commentSyntax: CommentSyntax, insertSpaces: boolean, detectIdentation: boolean): number {
if (indent === null) return 0;

if (detectIdentation) {
Expand All @@ -61,7 +63,8 @@ export class StringUtil {
if (insertSpaces) {
return indent.split(' ').length;
} else {
return indent.split('\t').length;
const offset = commentSyntax == CommentSyntax.delimited ? 1 : 0;
return indent.split('\t').length + offset;
}
}

Expand Down

0 comments on commit 292e837

Please sign in to comment.