Skip to content

Commit

Permalink
Fixed #98 ctrl-enter (insert line below, insert line above) in middle…
Browse files Browse the repository at this point in the history
… of line not adding
  • Loading branch information
kasecato committed Jul 26, 2020
1 parent 82c6d80 commit d4547e3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 0.1.15 (July 26, 2020)

* 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 - Delimited comment "/**" doen't work. See [#100](https://github.com/kasecato/vscode-docomment/issues/100).

## 0.1.14 (July 20, 2020)
Expand Down
8 changes: 8 additions & 0 deletions src/Domain/DocommentDomain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export class DocommentDomain implements IDocommentDomain {
// Detect Language
if (!this._vsCodeApi.IsLanguage(languageId)) return;

// Initalize
this.Init();

// Can Fire Document Comment
if (!this.IsTriggerDocomment()) return;

Expand Down Expand Up @@ -69,6 +72,11 @@ export class DocommentDomain implements IDocommentDomain {
* Domain Method
*-----------------------------------------------------------------------*/

/* @implements */
public Init() {
// NOP
}

/* @implements */
public IsTriggerDocomment(): boolean {
return false;
Expand Down
1 change: 1 addition & 0 deletions src/Domain/IDocommentDomain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface IDocommentDomain {
/*-------------------------------------------------------------------------
* Domain Method
*-----------------------------------------------------------------------*/
Init();
IsTriggerDocomment(): boolean;
GetCode(): string;
GetCodeType(code: string): CodeType;
Expand Down
30 changes: 25 additions & 5 deletions src/Domain/Lang/DocommentDomainCSharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ export class DocommentDomainCSharp extends DocommentDomain {
* Field
*-----------------------------------------------------------------------*/
private _isEnterKey: boolean = false;
private _isInsertDocCommentLineAbove: boolean = false;


/*-------------------------------------------------------------------------
* Domain Method
*-----------------------------------------------------------------------*/
/* @override */
public Init() {
this._isEnterKey = false;
this._isInsertDocCommentLineAbove = false;
}

/* @override */
public IsTriggerDocomment(): boolean {
Expand Down Expand Up @@ -70,12 +76,23 @@ export class DocommentDomainCSharp extends DocommentDomain {
return false;
}
}

// NG: '////'
else if (!SyntacticAnalysisCSharp.IsDocComment(activeLine, this._config.syntax)) {
return false;
const isInsertLineAbove = SyntacticAnalysisCSharp.IsInsertLineAbove(activeLine);
if (isInsertLineAbove) {
const nextLine = this._vsCodeApi.ReadNextLineFromCurrent();
const isInsertDocCommentLineAbove = SyntacticAnalysisCSharp.IsDocComment(nextLine, this._config.syntax);
if (!isInsertDocCommentLineAbove) {
return false;
}
this._isInsertDocCommentLineAbove = isInsertDocCommentLineAbove;
} else {
if (!SyntacticAnalysisCSharp.IsDocComment(activeLine, this._config.syntax)) {
return false;
}
}
// NG: Undo comment lines with the enter key
else if (SyntacticAnalysisCSharp.IsDocComment(eventText, this._config.syntax)) {
if (SyntacticAnalysisCSharp.IsDocComment(eventText, this._config.syntax)) {
return false;
}
}
Expand Down Expand Up @@ -194,7 +211,9 @@ export class DocommentDomainCSharp extends DocommentDomain {
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 insertPosition: Position = this._vsCodeApi.GetPosition(position.line + 1, indentLen - 1);
const lineOffset = this._isInsertDocCommentLineAbove ? 0 : 1;
const charOffset = this._isInsertDocCommentLineAbove ? 0 : -1;
const insertPosition: Position = this._vsCodeApi.GetPosition(position.line + lineOffset, indentLen + charOffset);
this._vsCodeApi.InsertText(insertPosition, docomment);
} else {
if (this._isEnterKey) {
Expand All @@ -216,8 +235,9 @@ export class DocommentDomainCSharp extends DocommentDomain {
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 line = curPosition.line + SyntacticAnalysisCSharp.GetLineOffset(this._config.syntax, codeType);
const lineOffset = this._isInsertDocCommentLineAbove ? -1 : 0;
const character = indentLen - 1 + docomment.length;
this._vsCodeApi.MoveSelection(line, character);
this._vsCodeApi.MoveSelection(line + lineOffset, character);
}

/*-------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions src/SyntacticAnalysis/SyntacticAnalysisCSharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export class SyntacticAnalysisCSharp {
return (activeChar === '') && (text.startsWith('\n') || text.startsWith("\r\n"));
}

public static IsInsertLineAbove(activeLine: string): boolean {
return activeLine !== null && activeLine.trim().length === 0 ;
}

public static IsActivationKey(activeChar: string, syntax: CommentSyntax): boolean {
switch (syntax) {
case CommentSyntax.single:
Expand Down

0 comments on commit d4547e3

Please sign in to comment.