Skip to content

Commit

Permalink
Disable tool window chat editor when initially displayed
Browse files Browse the repository at this point in the history
  • Loading branch information
carlrobertoh committed Nov 21, 2023
1 parent 53bdbcd commit ecf6ac0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import ee.carlrobert.codegpt.toolwindow.chat.ResponseNodeRenderer;
import ee.carlrobert.codegpt.toolwindow.chat.StreamParser;
import ee.carlrobert.codegpt.toolwindow.chat.StreamResponseType;
import ee.carlrobert.codegpt.toolwindow.chat.editor.ResponseEditor;
import ee.carlrobert.codegpt.toolwindow.chat.editor.ResponseEditorPanel;
import ee.carlrobert.codegpt.util.MarkdownUtil;
import ee.carlrobert.codegpt.util.UIUtil;
import ee.carlrobert.llm.client.you.completion.YouSerpResult;
Expand All @@ -46,7 +46,7 @@ public class ChatMessageResponseBody extends JPanel {
private final StreamParser streamParser;
private final boolean readOnly;
private JPanel currentlyProcessedElement;
private ResponseEditor currentlyProcessedEditor;
private ResponseEditorPanel currentlyProcessedEditor;
private JTextPane currentlyProcessedTextPane;
private boolean responseReceived;

Expand Down Expand Up @@ -248,7 +248,7 @@ private void prepareProcessingTextResponse() {
private void prepareProcessingCodeResponse(String code, String markdownLanguage) {
hideCarets();
currentlyProcessedTextPane = null;
currentlyProcessedEditor = new ResponseEditor(
currentlyProcessedEditor = new ResponseEditorPanel(
project,
code,
markdownLanguage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
import javax.swing.Box;
import javax.swing.JPanel;

public class ResponseEditor extends JPanel implements Disposable {
public class ResponseEditorPanel extends JPanel implements Disposable {

private final Editor editor;
private final String language;
private final String extension;

public ResponseEditor(
public ResponseEditorPanel(
Project project,
String code,
String markdownLanguage,
Expand All @@ -66,22 +66,7 @@ public ResponseEditor(
}
}

var editorEx = ((EditorEx) editor);
if (readOnly) {
editorEx.setOneLineMode(true);
editorEx.setHorizontalScrollbarVisible(false);
}
editorEx.installPopupHandler(new ContextMenuPopupHandler.Simple(group));
editorEx.setColorsScheme(EditorColorsManager.getInstance().getSchemeForCurrentUITheme());

var settings = editorEx.getSettings();
settings.setAdditionalColumnsCount(0);
settings.setAdditionalLinesCount(1);
settings.setAdditionalPageAtBottom(false);
settings.setVirtualSpace(false);
settings.setUseSoftWraps(false);
settings.setLineMarkerAreaShown(false);
settings.setGutterIconsShown(false);
configureEditor((EditorEx) editor, readOnly, new ContextMenuPopupHandler.Simple(group));

add(createHeaderComponent(readOnly), BorderLayout.NORTH);
add(editor.getComponent(), BorderLayout.CENTER);
Expand All @@ -99,6 +84,27 @@ public Editor getEditor() {
return editor;
}

private void configureEditor(
EditorEx editorEx,
boolean readOnly,
ContextMenuPopupHandler popupHandler) {
if (readOnly) {
editorEx.setOneLineMode(true);
editorEx.setHorizontalScrollbarVisible(false);
}
editorEx.installPopupHandler(popupHandler);
editorEx.setColorsScheme(EditorColorsManager.getInstance().getSchemeForCurrentUITheme());

var settings = editorEx.getSettings();
settings.setAdditionalColumnsCount(0);
settings.setAdditionalLinesCount(1);
settings.setAdditionalPageAtBottom(false);
settings.setVirtualSpace(false);
settings.setUseSoftWraps(false);
settings.setLineMarkerAreaShown(false);
settings.setGutterIconsShown(false);
}

private JPanel createHeaderComponent(boolean readOnly) {
var headerComponent = new JPanel(new BorderLayout());
headerComponent.setBorder(JBUI.Borders.compound(
Expand All @@ -114,8 +120,8 @@ private JPanel createHeaderComponent(boolean readOnly) {
private String getLinkText(boolean expanded) {
return expanded
? format(
CodeGPTBundle.get("toolwindow.chat.editor.action.expand"),
((EditorEx) editor).getDocument().getLineCount() - 1)
CodeGPTBundle.get("toolwindow.chat.editor.action.expand"),
((EditorEx) editor).getDocument().getLineCount() - 1)
: CodeGPTBundle.get("toolwindow.chat.editor.action.collapse");
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ee/carlrobert/codegpt/util/EditorUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static Editor createEditor(@NotNull Project project, String fileExtension
document,
project,
lightVirtualFile,
false,
true,
EditorKind.MAIN_EDITOR);
}

Expand Down

0 comments on commit ecf6ac0

Please sign in to comment.