Skip to content

Commit f031423

Browse files
committed
refactor: use indexOf for line comment
1 parent 7c46791 commit f031423

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/extension.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -466,13 +466,13 @@ export const toggleJSDocComment = async (): Promise<boolean> => {
466466

467467
// #region - no jsdoc exists but possibly block or line comment
468468
if (isSingleLineSelection) {
469-
const lineCommentTag = lineFirst.text.match(LINE_COMMENT_TAG)
469+
const lineCommentIndex = lineFirst.text.indexOf(LINE_COMMENT_TAG)
470470
const blockCommentStartIndex = lineFirst.text.indexOf(
471471
BLOCK_COMMENT_START_TAG
472472
)
473473
const blockCommentEndIndex = lineFirst.text.indexOf(BLOCK_COMMENT_END_TAG)
474474
const isLineCommentFullLine =
475-
lineFirst.firstNonWhitespaceCharacterIndex === lineCommentTag?.index
475+
lineFirst.firstNonWhitespaceCharacterIndex === lineCommentIndex
476476
const isBlockCommentTrailing =
477477
lineFirst.firstNonWhitespaceCharacterIndex !== blockCommentStartIndex &&
478478
(lineFirst.text.length - BLOCK_COMMENT_END_TAG.length ===
@@ -484,7 +484,7 @@ export const toggleJSDocComment = async (): Promise<boolean> => {
484484
hasSelection(editor) &&
485485
!jsdocStart?.index &&
486486
!jsdocEnd?.index &&
487-
!lineCommentTag?.index &&
487+
lineCommentIndex === -1 &&
488488
blockCommentStartIndex === -1 &&
489489
blockCommentEndIndex === -1
490490
) {
@@ -600,8 +600,8 @@ export const toggleJSDocComment = async (): Promise<boolean> => {
600600
)
601601
}
602602
} else if (
603-
lineCommentTag?.index !== undefined &&
604-
editor.selection.active.character > lineCommentTag.index
603+
lineCommentIndex > -1 &&
604+
editor.selection.active.character > lineCommentIndex
605605
) {
606606
log("converting line comment to jsdoc")
607607
const firstChar = editor.document.getText(
@@ -624,9 +624,9 @@ export const toggleJSDocComment = async (): Promise<boolean> => {
624624
editBuilder.replace(
625625
new vscode.Range(
626626
lineFirst.lineNumber,
627-
lineCommentTag.index,
627+
lineCommentIndex,
628628
lineFirst.lineNumber,
629-
lineCommentTag.index + lineCommentTag[0].length
629+
lineCommentIndex + LINE_COMMENT_TAG.length
630630
),
631631
""
632632
)
@@ -640,9 +640,9 @@ export const toggleJSDocComment = async (): Promise<boolean> => {
640640
editBuilder.replace(
641641
new vscode.Range(
642642
lineFirst.lineNumber,
643-
lineCommentTag.index,
643+
lineCommentIndex,
644644
lineFirst.lineNumber,
645-
lineCommentTag.index + lineCommentTag[0].length
645+
lineCommentIndex + LINE_COMMENT_TAG.length
646646
),
647647
"*"
648648
)
@@ -683,7 +683,7 @@ export const toggleJSDocComment = async (): Promise<boolean> => {
683683
.getText(
684684
new vscode.Range(
685685
getContentStartPos(lineFirst),
686-
new vscode.Position(lineFirst.lineNumber, lineCommentTag.index)
686+
new vscode.Position(lineFirst.lineNumber, lineCommentIndex)
687687
)
688688
)
689689
.trim()
@@ -693,7 +693,7 @@ export const toggleJSDocComment = async (): Promise<boolean> => {
693693
new vscode.Range(
694694
new vscode.Position(
695695
lineFirst.lineNumber,
696-
lineCommentTag.index + LINE_COMMENT_TAG.length
696+
lineCommentIndex + LINE_COMMENT_TAG.length
697697
),
698698
editor.selection.active
699699
)

0 commit comments

Comments
 (0)