Skip to content

Commit 66c2e96

Browse files
committed
feat(icon): add support for auto dev insert file action
This commit modifies the `AutoDevInsertToCodeAction.kt` file in order to add support for the auto dev insert file action in the GUI. It imports `PlatformDataKeys` to access editor data and performs a command action to insert selected text or the entire text into the editor.
1 parent f56d7de commit 66c2e96

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/main/kotlin/cc/unitmesh/devti/gui/snippet/AutoDevInsertToCodeAction.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,22 @@ package cc.unitmesh.devti.gui.snippet
22

33
import com.intellij.openapi.actionSystem.ActionUpdateThread
44
import com.intellij.openapi.actionSystem.AnActionEvent
5+
import com.intellij.openapi.actionSystem.PlatformDataKeys
56
import com.intellij.openapi.command.WriteCommandAction
67
import com.intellij.openapi.fileEditor.FileEditorManager
78
import com.intellij.openapi.project.DumbAwareAction
8-
import com.intellij.openapi.util.TextRange
99

1010
class AutoDevInsertFileAction : DumbAwareAction() {
1111
override fun actionPerformed(e: AnActionEvent) {
12-
val editor = e.getData(com.intellij.openapi.actionSystem.PlatformDataKeys.EDITOR) ?: return
12+
val project = e.project ?: return
13+
val editor = e.getData(PlatformDataKeys.EDITOR) ?: return
1314
val selectionModel = if (editor.selectionModel.hasSelection()) editor.selectionModel else null
1415
val textToPaste = selectionModel?.selectedText ?: editor.document.text.trimEnd()
1516

16-
val project = e.project ?: return
17-
1817
val selectedTextEditor = FileEditorManager.getInstance(project).selectedTextEditor
19-
WriteCommandAction.writeCommandAction(project).compute<TextRange, RuntimeException> {
18+
WriteCommandAction.writeCommandAction(project).compute<Any, RuntimeException> {
2019
val offset = selectionModel?.selectionStart ?: selectedTextEditor?.document?.textLength ?: return@compute null
2120
selectedTextEditor?.document?.insertString(offset, textToPaste)
22-
TextRange.from(offset, textToPaste.length)
2321
}
2422
}
2523

0 commit comments

Comments
 (0)