diff --git a/DESCRIPTION.md b/DESCRIPTION.md index aae35b79..ebfbb221 100644 --- a/DESCRIPTION.md +++ b/DESCRIPTION.md @@ -26,6 +26,10 @@ CodeGPT offers a wide range of features to enhance your development experience: Get instant coding advice through a ChatGPT-like interface that accepts image input. Ask questions, share screenshots, seek explanations, or get guidance on your projects without leaving your IDE. +### Auto Apply + +Automatically insert AI-suggested code directly into your active file. Click the Auto Apply icon to stream changes, view them in diff style, and approve or reject edits directly. + **Use images** Chat with your images. Upload manually or let CodeGPT auto-detect your screenshots. diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c16dd51d..5124a9ea 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -12,7 +12,7 @@ jsoup = "1.17.2" jtokkit = "1.1.0" junit = "5.11.0" kotlin = "2.0.0" -llm-client = "0.8.22" +llm-client = "0.8.23" okio = "3.9.0" tree-sitter = "0.22.6a" diff --git a/src/main/java/ee/carlrobert/codegpt/Icons.java b/src/main/java/ee/carlrobert/codegpt/Icons.java index d86d3d88..b3e26715 100644 --- a/src/main/java/ee/carlrobert/codegpt/Icons.java +++ b/src/main/java/ee/carlrobert/codegpt/Icons.java @@ -28,6 +28,9 @@ public final class Icons { public static final Icon Ollama = IconLoader.getIcon("/icons/ollama.svg", Icons.class); public static final Icon User = IconLoader.getIcon("/icons/user.svg", Icons.class); public static final Icon Upload = IconLoader.getIcon("/icons/upload.svg", Icons.class); + public static final Icon Lightning = IconLoader.getIcon("/icons/lightning.svg", Icons.class); + public static final Icon LightningDisabled = + IconLoader.getIcon("/icons/lightning.svg", Icons.class); public static final Icon GreenCheckmark = IconLoader.getIcon("/icons/greenCheckmark.svg", Icons.class); public static final Icon SendToTheLeft = diff --git a/src/main/java/ee/carlrobert/codegpt/actions/ActionType.java b/src/main/java/ee/carlrobert/codegpt/actions/ActionType.java index f8ab4a56..5a3d51b4 100644 --- a/src/main/java/ee/carlrobert/codegpt/actions/ActionType.java +++ b/src/main/java/ee/carlrobert/codegpt/actions/ActionType.java @@ -12,6 +12,7 @@ public enum ActionType { EDIT_CODE, CREATE_NEW_FILE, COPY_CODE, + AUTO_APPLY, REPLACE_IN_MAIN_EDITOR, INSERT_AT_CARET, RELOAD_MESSAGE, diff --git a/src/main/java/ee/carlrobert/codegpt/actions/TrackableAction.java b/src/main/java/ee/carlrobert/codegpt/actions/TrackableAction.java index 66ad38ee..92343967 100644 --- a/src/main/java/ee/carlrobert/codegpt/actions/TrackableAction.java +++ b/src/main/java/ee/carlrobert/codegpt/actions/TrackableAction.java @@ -2,7 +2,6 @@ package ee.carlrobert.codegpt.actions; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.editor.Editor; import ee.carlrobert.codegpt.telemetry.TelemetryAction; import javax.swing.Icon; import org.jetbrains.annotations.NotNull; @@ -10,16 +9,13 @@ import org.jetbrains.annotations.NotNull; public abstract class TrackableAction extends AnAction { private final ActionType actionType; - protected final Editor editor; public TrackableAction( - @NotNull Editor editor, String text, String description, Icon icon, ActionType actionType) { super(text, description, icon); - this.editor = editor; this.actionType = actionType; } diff --git a/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/ToolWindowCompletionResponseEventListener.java b/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/ToolWindowCompletionResponseEventListener.java index d03a1c17..d6d307f4 100644 --- a/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/ToolWindowCompletionResponseEventListener.java +++ b/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/ToolWindowCompletionResponseEventListener.java @@ -116,7 +116,6 @@ abstract class ToolWindowCompletionResponseEventListener implements ApplicationManager.getApplication().invokeLater(() -> { try { responsePanel.enableActions(); - responseContainer.enableActions(); if (!responseContainer.isResponseReceived() && !fullMessage.isEmpty()) { responseContainer.withResponse(fullMessage); } diff --git a/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/editor/ResponseEditorPanel.java b/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/editor/ResponseEditorPanel.java index 6e7643e4..a8b593c5 100644 --- a/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/editor/ResponseEditorPanel.java +++ b/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/editor/ResponseEditorPanel.java @@ -11,7 +11,6 @@ import com.intellij.openapi.actionSystem.ActionToolbar; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DefaultActionGroup; -import com.intellij.openapi.actionSystem.DefaultCompactActionGroup; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorFactory; import com.intellij.openapi.editor.colors.EditorColorsManager; @@ -28,19 +27,15 @@ import com.intellij.ui.components.ActionLink; import com.intellij.util.ui.JBUI; import ee.carlrobert.codegpt.CodeGPTBundle; import ee.carlrobert.codegpt.actions.toolwindow.ReplaceCodeInMainEditorAction; -import ee.carlrobert.codegpt.toolwindow.chat.CompareWithOriginalActionLink; -import ee.carlrobert.codegpt.toolwindow.chat.DirectApplyActionLink; +import ee.carlrobert.codegpt.toolwindow.chat.editor.actions.AutoApplyAction; import ee.carlrobert.codegpt.toolwindow.chat.editor.actions.CopyAction; import ee.carlrobert.codegpt.toolwindow.chat.editor.actions.DiffAction; import ee.carlrobert.codegpt.toolwindow.chat.editor.actions.EditAction; import ee.carlrobert.codegpt.toolwindow.chat.editor.actions.InsertAtCaretAction; import ee.carlrobert.codegpt.toolwindow.chat.editor.actions.NewFileAction; import ee.carlrobert.codegpt.toolwindow.chat.editor.actions.ReplaceSelectionAction; -import ee.carlrobert.codegpt.ui.IconActionButton; import ee.carlrobert.codegpt.util.EditorUtil; import java.awt.BorderLayout; -import java.awt.FlowLayout; -import javax.swing.Box; import javax.swing.JPanel; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -48,7 +43,6 @@ import org.jetbrains.annotations.Nullable; public class ResponseEditorPanel extends JPanel implements Disposable { private final Editor editor; - private final JPanel directLinksPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING, 0, 0)); public ResponseEditorPanel( Project project, @@ -75,28 +69,16 @@ public class ResponseEditorPanel extends JPanel implements Disposable { } } configureEditor( + project, (EditorEx) editor, readOnly, new ContextMenuPopupHandler.Simple(group), findLanguageExtensionMapping(markdownLanguage).getValue()); add(editor.getComponent(), BorderLayout.CENTER); - if (highlightedText != null && !highlightedText.isEmpty()) { - directLinksPanel.setVisible(false); - directLinksPanel.setBorder(JBUI.Borders.emptyTop(8)); - directLinksPanel.add(new CompareWithOriginalActionLink(project, editor, highlightedText)); - directLinksPanel.add(Box.createHorizontalStrut(12)); - directLinksPanel.add(new DirectApplyActionLink(project, editor, highlightedText)); - add(directLinksPanel, BorderLayout.SOUTH); - } - Disposer.register(disposableParent, this); } - public void showEditorActions() { - directLinksPanel.setVisible(true); - } - @Override public void dispose() { EditorFactory.getInstance().releaseEditor(editor); @@ -107,6 +89,7 @@ public class ResponseEditorPanel extends JPanel implements Disposable { } private void configureEditor( + Project project, EditorEx editorEx, boolean readOnly, ContextMenuPopupHandler popupHandler, @@ -133,22 +116,28 @@ public class ResponseEditorPanel extends JPanel implements Disposable { editorEx.setVerticalScrollbarVisible(false); editorEx.getContentComponent().setBorder(JBUI.Borders.emptyLeft(4)); editorEx.setBorder(IdeBorderFactory.createBorder(ColorUtil.fromHex("#48494b"))); - editorEx.setPermanentHeaderComponent(createHeaderComponent(editorEx, extension, readOnly)); + editorEx.setPermanentHeaderComponent( + createHeaderComponent(project, editorEx, extension, readOnly)); editorEx.setHeaderComponent(null); } - private JPanel createHeaderComponent(EditorEx editorEx, String extension, boolean readOnly) { - var headerComponent = new JPanel(new BorderLayout()); - headerComponent.setBorder( + private JPanel createHeaderComponent( + Project project, + EditorEx editorEx, + String extension, + boolean readOnly) { + var headerPanel = new JPanel(new BorderLayout()); + headerPanel.setBorder( JBUI.Borders.compound( JBUI.Borders.customLine(ColorUtil.fromHex("#48494b"), 1, 1, 0, 1), JBUI.Borders.empty(4))); - headerComponent.add(createExpandLink(editorEx), BorderLayout.LINE_START); + headerPanel.add(createExpandLink(editorEx), BorderLayout.LINE_START); if (!readOnly) { - headerComponent.add( - createHeaderActions(extension, editorEx).getComponent(), BorderLayout.LINE_END); + headerPanel.add( + createHeaderActions(project, extension, editorEx, headerPanel).getComponent(), + BorderLayout.LINE_END); } - return headerComponent; + return headerPanel; } private String getLinkText(boolean expanded) { @@ -178,20 +167,20 @@ public class ResponseEditorPanel extends JPanel implements Disposable { return expandLink; } - private ActionToolbar createHeaderActions(String extension, EditorEx editorEx) { - var actionGroup = new DefaultCompactActionGroup("EDITOR_TOOLBAR_ACTION_GROUP", false); - actionGroup.add(new CopyAction(editor)); - actionGroup.add(new ReplaceSelectionAction(editor)); - actionGroup.add(new InsertAtCaretAction(editor)); + private ActionToolbar createHeaderActions( + Project project, + String extension, + EditorEx editorEx, + JPanel headerPanel) { + var actionGroup = new DefaultActionGroup("EDITOR_TOOLBAR_ACTION_GROUP", false); + actionGroup.add(new AutoApplyAction(project, editorEx, headerPanel)); + actionGroup.add(new InsertAtCaretAction(editorEx)); + actionGroup.add(new CopyAction(editorEx)); actionGroup.addSeparator(); - var wrapper = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); - wrapper.add(new IconActionButton(new CopyAction(editor))); - wrapper.add(Box.createHorizontalStrut(4)); - wrapper.add(new IconActionButton(new ReplaceSelectionAction(editor))); - var menu = new JBPopupMenu(); menu.add(new JBMenuItem(new DiffAction(editorEx, menu.getLocation()))); + menu.add(new JBMenuItem(new ReplaceSelectionAction(editorEx, menu.getLocation()))); menu.add(new JBMenuItem(new EditAction(editorEx))); menu.add(new JBMenuItem(new NewFileAction(editorEx, extension))); diff --git a/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/editor/actions/CopyAction.java b/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/editor/actions/CopyAction.java index 6823fdfc..2d5a76d2 100644 --- a/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/editor/actions/CopyAction.java +++ b/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/editor/actions/CopyAction.java @@ -15,18 +15,20 @@ import org.jetbrains.annotations.NotNull; public class CopyAction extends TrackableAction { - public CopyAction(@NotNull Editor editor) { + private final @NotNull Editor toolwindowEditor; + + public CopyAction(@NotNull Editor toolwindowEditor) { super( - editor, CodeGPTBundle.get("toolwindow.chat.editor.action.copy.title"), CodeGPTBundle.get("toolwindow.chat.editor.action.copy.description"), Actions.Copy, ActionType.COPY_CODE); + this.toolwindowEditor = toolwindowEditor; } @Override public void handleAction(@NotNull AnActionEvent event) { - StringSelection stringSelection = new StringSelection(editor.getDocument().getText()); + StringSelection stringSelection = new StringSelection(toolwindowEditor.getDocument().getText()); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, null); @@ -36,8 +38,8 @@ public class CopyAction extends TrackableAction { locationOnScreen.y = locationOnScreen.y - 16; OverlayUtil.showInfoBalloon( - CodeGPTBundle.get("toolwindow.chat.editor.action.copy.success"), - locationOnScreen); + CodeGPTBundle.get("toolwindow.chat.editor.action.copy.success"), + locationOnScreen); } } } diff --git a/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/editor/actions/DiffAction.java b/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/editor/actions/DiffAction.java index b1ea4d4c..98f6c1f1 100644 --- a/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/editor/actions/DiffAction.java +++ b/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/editor/actions/DiffAction.java @@ -19,7 +19,7 @@ public class DiffAction extends AbstractAction { private final Point locationOnScreen; public DiffAction(EditorEx editor, @Nullable Point locationOnScreen) { - super("Diff", Actions.DiffWithClipboard); + super("Diff Selection", Actions.DiffWithClipboard); this.editor = editor; this.locationOnScreen = locationOnScreen; } @@ -28,7 +28,7 @@ public class DiffAction extends AbstractAction { public void actionPerformed(ActionEvent event) { var project = requireNonNull(editor.getProject()); var mainEditor = FileEditorManager.getInstance(project).getSelectedTextEditor(); - if (mainEditor != null && !EditorUtil.hasSelection(mainEditor) && locationOnScreen != null) { + if (mainEditor == null || !EditorUtil.hasSelection(mainEditor)) { OverlayUtil.showSelectedEditorSelectionWarning(project, locationOnScreen); return; } @@ -36,6 +36,6 @@ public class DiffAction extends AbstractAction { EditorDiffUtil.showDiff( project, editor, - mainEditor.getSelectionModel().getSelectedText()); + requireNonNull(mainEditor.getSelectionModel().getSelectedText())); } } diff --git a/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/editor/actions/InsertAtCaretAction.java b/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/editor/actions/InsertAtCaretAction.java index 015bdd7f..a8160cb0 100644 --- a/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/editor/actions/InsertAtCaretAction.java +++ b/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/editor/actions/InsertAtCaretAction.java @@ -17,13 +17,15 @@ import org.jetbrains.annotations.Nullable; public class InsertAtCaretAction extends TrackableAction { - public InsertAtCaretAction(@NotNull Editor editor) { + private final @NotNull Editor toolwindowEditor; + + public InsertAtCaretAction(@NotNull Editor toolwindowEditor) { super( - editor, CodeGPTBundle.get("toolwindow.chat.editor.action.insertAtCaret.title"), CodeGPTBundle.get("toolwindow.chat.editor.action.insertAtCaret.description"), Icons.SendToTheLeft, ActionType.INSERT_AT_CARET); + this.toolwindowEditor = toolwindowEditor; } @Override @@ -48,7 +50,7 @@ public class InsertAtCaretAction extends TrackableAction { @Nullable private Editor getSelectedTextEditor() { - return Optional.ofNullable(editor.getProject()) + return Optional.ofNullable(toolwindowEditor.getProject()) .map(FileEditorManager::getInstance) .map(FileEditorManager::getSelectedTextEditor) .orElse(null); @@ -58,7 +60,7 @@ public class InsertAtCaretAction extends TrackableAction { runUndoTransparentWriteAction(() -> { mainEditor.getDocument().insertString( mainEditor.getCaretModel().getOffset(), - editor.getDocument().getText()); + toolwindowEditor.getDocument().getText()); return null; }); } diff --git a/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/editor/actions/ReplaceSelectionAction.java b/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/editor/actions/ReplaceSelectionAction.java index 6bfd0b8c..ea30c412 100644 --- a/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/editor/actions/ReplaceSelectionAction.java +++ b/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/editor/actions/ReplaceSelectionAction.java @@ -3,36 +3,41 @@ package ee.carlrobert.codegpt.toolwindow.chat.editor.actions; import static java.util.Objects.requireNonNull; import com.intellij.icons.AllIcons.Actions; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.ex.EditorEx; import ee.carlrobert.codegpt.CodeGPTBundle; -import ee.carlrobert.codegpt.actions.ActionType; -import ee.carlrobert.codegpt.actions.TrackableAction; import ee.carlrobert.codegpt.ui.OverlayUtil; import ee.carlrobert.codegpt.util.EditorUtil; +import java.awt.Point; +import java.awt.event.ActionEvent; +import javax.swing.AbstractAction; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -public class ReplaceSelectionAction extends TrackableAction { +public class ReplaceSelectionAction extends AbstractAction { - public ReplaceSelectionAction(@NotNull Editor editor) { + private final @NotNull EditorEx toolwindowEditor; + private final Point locationOnScreen; + + public ReplaceSelectionAction( + @NotNull EditorEx toolwindowEditor, + @Nullable Point locationOnScreen) { super( - editor, CodeGPTBundle.get("toolwindow.chat.editor.action.replaceSelection.title"), - CodeGPTBundle.get("toolwindow.chat.editor.action.replaceSelection.description"), - Actions.Replace, - ActionType.REPLACE_IN_MAIN_EDITOR); + Actions.Replace); + this.toolwindowEditor = toolwindowEditor; + this.locationOnScreen = locationOnScreen; } @Override - public void handleAction(@NotNull AnActionEvent event) { - var project = requireNonNull(event.getProject()); + public void actionPerformed(ActionEvent event) { + var project = requireNonNull(toolwindowEditor.getProject()); if (EditorUtil.isMainEditorTextSelected(project)) { var mainEditor = EditorUtil.getSelectedEditor(project); if (mainEditor != null) { - EditorUtil.replaceEditorSelection(mainEditor, editor.getDocument().getText()); + EditorUtil.replaceEditorSelection(mainEditor, toolwindowEditor.getDocument().getText()); } } else { - OverlayUtil.showSelectedEditorSelectionWarning(event); + OverlayUtil.showSelectedEditorSelectionWarning(project, locationOnScreen); } } } diff --git a/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/ui/ChatMessageResponseBody.java b/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/ui/ChatMessageResponseBody.java index 57998ea1..58ca66dc 100644 --- a/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/ui/ChatMessageResponseBody.java +++ b/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/ui/ChatMessageResponseBody.java @@ -98,14 +98,6 @@ public class ChatMessageResponseBody extends JPanel { } } - public void enableActions() { - if (highlightedText != null - && !highlightedText.isEmpty() - && currentlyProcessedEditorPanel != null) { - currentlyProcessedEditorPanel.showEditorActions(); - } - } - public ChatMessageResponseBody withResponse(String response) { try { for (var message : MarkdownUtil.splitCodeBlocks(response)) { @@ -173,7 +165,7 @@ public class ChatMessageResponseBody extends JPanel { "
%s
", message); if (responseReceived) { - add(createTextPane(errorText, false)); + add(createTextPane(errorText)); } else { currentlyProcessedTextPane.setText(errorText); } @@ -269,12 +261,6 @@ public class ChatMessageResponseBody extends JPanel { } private void prepareProcessingText(boolean caretVisible) { - if (highlightedText != null - && !highlightedText.isEmpty() - && currentlyProcessedEditorPanel != null) { - currentlyProcessedEditorPanel.showEditorActions(); - } - currentlyProcessedEditorPanel = null; currentlyProcessedTextPane = createTextPane("", caretVisible); add(currentlyProcessedTextPane); @@ -316,6 +302,10 @@ public class ChatMessageResponseBody extends JPanel { } } + private JTextPane createTextPane(String text) { + return createTextPane(text, false); + } + private JTextPane createTextPane(String text, boolean caretVisible) { var textPane = UIUtil.createTextPane(text, false, event -> { if (FileUtil.exists(event.getDescription()) && ACTIVATED.equals(event.getEventType())) { diff --git a/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/ui/ResponsePanel.java b/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/ui/ResponsePanel.java index 9c813fd9..235ec7d8 100644 --- a/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/ui/ResponsePanel.java +++ b/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/ui/ResponsePanel.java @@ -128,7 +128,7 @@ public class ResponsePanel extends JPanel { Body() { super(new BorderLayout()); - setBorder(JBUI.Borders.empty(4, 8, 8, 8)); + setBorder(JBUI.Borders.empty(4, 8)); } public void addContent(JComponent content) { diff --git a/src/main/kotlin/ee/carlrobert/codegpt/events/CodeGPTEvent.kt b/src/main/kotlin/ee/carlrobert/codegpt/events/CodeGPTEvent.kt index c4b19706..b963b795 100644 --- a/src/main/kotlin/ee/carlrobert/codegpt/events/CodeGPTEvent.kt +++ b/src/main/kotlin/ee/carlrobert/codegpt/events/CodeGPTEvent.kt @@ -26,7 +26,7 @@ data class Event @JsonCreator constructor( ANALYZE_WEB_DOC_COMPLETED, ANALYZE_WEB_DOC_FAILED, PROCESS_CONTEXT, - WEB_SEARCH_ITEM + WEB_SEARCH_ITEM, } } diff --git a/src/main/kotlin/ee/carlrobert/codegpt/toolwindow/chat/CompareWithOriginalActionLink.kt b/src/main/kotlin/ee/carlrobert/codegpt/toolwindow/chat/CompareWithOriginalActionLink.kt deleted file mode 100644 index 6927ff10..00000000 --- a/src/main/kotlin/ee/carlrobert/codegpt/toolwindow/chat/CompareWithOriginalActionLink.kt +++ /dev/null @@ -1,36 +0,0 @@ -package ee.carlrobert.codegpt.toolwindow.chat - -import com.intellij.icons.AllIcons.Actions -import com.intellij.openapi.actionSystem.AnAction -import com.intellij.openapi.actionSystem.AnActionEvent -import com.intellij.openapi.editor.Editor -import com.intellij.openapi.project.Project -import ee.carlrobert.codegpt.CodeGPTBundle -import ee.carlrobert.codegpt.util.EditorDiffUtil - -class CompareWithOriginalActionLink( - project: Project, - toolwindowEditor: Editor, - highlightedText: String, -) : ToolwindowEditorActionLink( - project, - CodeGPTBundle.get("action.compareWithOriginal.title"), - CompareWithOriginalAction(project, toolwindowEditor, highlightedText), - highlightedText -) { - - init { - setIcon(Actions.Diff) - } - - class CompareWithOriginalAction( - private val project: Project, - private val toolwindowEditor: Editor, - private val highlightedText: String - ) : AnAction() { - - override fun actionPerformed(e: AnActionEvent) { - EditorDiffUtil.showDiff(project, toolwindowEditor, highlightedText) - } - } -} diff --git a/src/main/kotlin/ee/carlrobert/codegpt/toolwindow/chat/DirectApplyActionLink.kt b/src/main/kotlin/ee/carlrobert/codegpt/toolwindow/chat/DirectApplyActionLink.kt deleted file mode 100644 index 09a6863f..00000000 --- a/src/main/kotlin/ee/carlrobert/codegpt/toolwindow/chat/DirectApplyActionLink.kt +++ /dev/null @@ -1,52 +0,0 @@ -package ee.carlrobert.codegpt.toolwindow.chat - -import com.intellij.icons.AllIcons.Actions -import com.intellij.openapi.actionSystem.AnAction -import com.intellij.openapi.actionSystem.AnActionEvent -import com.intellij.openapi.command.WriteCommandAction -import com.intellij.openapi.editor.Editor -import com.intellij.openapi.editor.ScrollType -import com.intellij.openapi.fileEditor.FileEditorManager -import com.intellij.openapi.project.Project -import ee.carlrobert.codegpt.CodeGPTBundle - -class DirectApplyActionLink( - project: Project, - toolwindowEditor: Editor, - highlightedText: String, -) : ToolwindowEditorActionLink( - project, - CodeGPTBundle.get("action.applyDirectly.title"), - DirectApplyAction(project, toolwindowEditor, highlightedText), - highlightedText -) { - - init { - setIcon(Actions.Selectall) - } - - class DirectApplyAction( - private val project: Project, - private val toolwindowEditor: Editor, - private val highlightedText: String - ) : AnAction() { - - override fun actionPerformed(e: AnActionEvent) { - val mainEditor = FileEditorManager.getInstance(project).selectedTextEditor - ?: throw IllegalStateException("No editor selected") - val startIndex = mainEditor.document.text.indexOf(highlightedText) - if (startIndex == -1) { - return - } - - val endIndex = startIndex + highlightedText.length - val replacement = toolwindowEditor.document.text - - WriteCommandAction.runWriteCommandAction(project) { - mainEditor.document.replaceString(startIndex, endIndex, replacement) - mainEditor.caretModel.moveToOffset(startIndex + replacement.length) - mainEditor.scrollingModel.scrollToCaret(ScrollType.CENTER) - } - } - } -} diff --git a/src/main/kotlin/ee/carlrobert/codegpt/toolwindow/chat/ToolwindowEditorActionLink.kt b/src/main/kotlin/ee/carlrobert/codegpt/toolwindow/chat/ToolwindowEditorActionLink.kt deleted file mode 100644 index 27ecf29a..00000000 --- a/src/main/kotlin/ee/carlrobert/codegpt/toolwindow/chat/ToolwindowEditorActionLink.kt +++ /dev/null @@ -1,39 +0,0 @@ -package ee.carlrobert.codegpt.toolwindow.chat - -import com.intellij.openapi.actionSystem.AnAction -import com.intellij.openapi.application.runInEdt -import com.intellij.openapi.components.service -import com.intellij.openapi.editor.event.DocumentEvent -import com.intellij.openapi.editor.event.DocumentListener -import com.intellij.openapi.fileEditor.FileEditorManager -import com.intellij.openapi.project.Project -import com.intellij.ui.components.AnActionLink - -open class ToolwindowEditorActionLink( - private val project: Project, - title: String, - action: AnAction, - private val highlightedText: String, -) : AnActionLink(title, action) { - - private val mainEditor = project.service