@@ -7,10 +7,6 @@ import com.intellij.openapi.editor.Editor
77import com.intellij.openapi.fileEditor.FileEditorManager
88import com.intellij.openapi.project.Project
99import com.intellij.openapi.util.TextRange
10- import org.jetbrains.kotlin.idea.base.psi.getLineNumber
11- import org.polyfrost.intelliprocessor.utils.PreprocessorContainingBlock
12- import org.polyfrost.intelliprocessor.utils.activeFile
13- import org.polyfrost.intelliprocessor.utils.allPreprocessorDirectiveComments
1410
1511class PreprocessorCommentToggleLineAction : AnAction () {
1612
@@ -19,26 +15,28 @@ class PreprocessorCommentToggleLineAction : AnAction() {
1915 val editor: Editor = FileEditorManager .getInstance(project).selectedTextEditor ? : return warning(project, " Could not find an open editor" )
2016 val document = editor.document
2117
22- val startLine = editor.caretModel.primaryCaret.selectionStartPosition.line
23- val endLine = editor.caretModel.primaryCaret.selectionEndPosition.line
18+ val startLine = document.getLineNumber( editor.selectionModel.selectionStart)
19+ val endLine = document.getLineNumber( editor.selectionModel.selectionEnd)
2420
2521 WriteCommandAction .runWriteCommandAction(project) {
2622 for (line in startLine.. endLine) {
2723 val lineStart = document.getLineStartOffset(line)
2824 val lineEnd = document.getLineEndOffset(line)
2925 val text = document.getText(TextRange (lineStart, lineEnd))
30-
31- val toggleCommentsOff = text.contains(" //$$" )
32-
33- // Clean up any existing toggle comments
34- document.replaceString(lineStart, lineEnd, text.replaceFirst(REPLACE , " " ))
35-
36- if (toggleCommentsOff) return @runWriteCommandAction
26+ val trim = text.trim()
3727
3828 // If the line is blank, just insert a blank comment
39- if (text. trim() .isEmpty()) {
29+ if (trim.isEmpty()) {
4030 document.replaceString(lineStart, lineEnd, " //$$ " )
41- return @runWriteCommandAction
31+ continue
32+ }
33+
34+ if (trim.startsWith(" //#" )) continue
35+
36+ if (trim.startsWith(" //$$" )) {
37+ // Clean up any existing toggle comments
38+ document.replaceString(lineStart, lineEnd, text.replaceFirst(REPLACE , " " ))
39+ continue
4240 }
4341
4442 // Only comment lines that are indented at least as much as the block start
0 commit comments