Skip to content

Commit 658e78f

Browse files
committed
fix: hide webpage list on any interrupted event
1 parent 509b43f commit 658e78f

File tree

1 file changed

+44
-17
lines changed

1 file changed

+44
-17
lines changed

src/main/java/ee/carlrobert/codegpt/toolwindow/chat/ui/ChatMessageResponseBody.java

+44-17
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ public class ChatMessageResponseBody extends JPanel {
4141
private final StreamParser streamParser;
4242
private final boolean readOnly;
4343
private final DefaultListModel<Details> webpageListModel = new DefaultListModel<>();
44+
private final WebpageList webpageList = new WebpageList(webpageListModel);
4445
private ResponseEditorPanel currentlyProcessedEditorPanel;
4546
private JTextPane currentlyProcessedTextPane;
47+
private JPanel webpageListPanel;
4648
private boolean responseReceived;
4749

4850
public ChatMessageResponseBody(Project project, Disposable parentDisposable) {
@@ -71,17 +73,10 @@ public ChatMessageResponseBody(
7173
setOpaque(false);
7274

7375
if (webSearchIncluded) {
74-
var title = new JPanel(new BorderLayout());
75-
title.setOpaque(false);
76-
title.setBorder(JBUI.Borders.empty(8, 0));
77-
title.add(new JBLabel(CodeGPTBundle.get("chatMessageResponseBody.webPagesTitle"))
78-
.withFont(JBUI.Fonts.miniFont()), BorderLayout.LINE_START);
79-
add(title);
80-
81-
var listPanel = new JPanel(new BorderLayout());
82-
listPanel.add(new WebpageList(webpageListModel), BorderLayout.LINE_START);
83-
add(listPanel);
76+
webpageListPanel = createWebpageListPanel(webpageList);
77+
add(webpageListPanel);
8478
}
79+
8580
if (withGhostText) {
8681
prepareProcessingText(!readOnly);
8782
currentlyProcessedTextPane.setText(
@@ -113,7 +108,11 @@ public void displayMissingCredential() {
113108
.showSettingsDialog(project, GeneralSettingsConfigurable.class);
114109
}
115110
});
116-
currentlyProcessedTextPane.getCaret().setVisible(false);
111+
hideCaret();
112+
113+
if (webpageListPanel != null) {
114+
webpageListPanel.setVisible(false);
115+
}
117116
}
118117

119118
public void displayQuotaExceeded() {
@@ -133,11 +132,9 @@ public void displayQuotaExceeded() {
133132
}
134133
});
135134
hideCaret();
136-
}
137135

138-
public void hideCaret() {
139-
if (currentlyProcessedTextPane != null) {
140-
currentlyProcessedTextPane.getCaret().setVisible(false);
136+
if (webpageListPanel != null) {
137+
webpageListPanel.setVisible(false);
141138
}
142139
}
143140

@@ -150,6 +147,23 @@ public void displayError(String message) {
150147
} else {
151148
currentlyProcessedTextPane.setText(errorText);
152149
}
150+
hideCaret();
151+
152+
if (webpageListPanel != null) {
153+
webpageListPanel.setVisible(false);
154+
}
155+
}
156+
157+
public void displayWebSearchItem(Details details) {
158+
webpageListModel.addElement(details);
159+
webpageList.revalidate();
160+
webpageList.repaint();
161+
}
162+
163+
public void hideCaret() {
164+
if (currentlyProcessedTextPane != null) {
165+
currentlyProcessedTextPane.getCaret().setVisible(false);
166+
}
153167
}
154168

155169
public void clear() {
@@ -229,7 +243,20 @@ private JTextPane createTextPane(String text, boolean caretVisible) {
229243
return textPane;
230244
}
231245

232-
public void displayWebSearchItem(Details details) {
233-
webpageListModel.addElement(details);
246+
private static JPanel createWebpageListPanel(WebpageList webpageList) {
247+
var panel = new JPanel(new BorderLayout());
248+
249+
var title = new JPanel(new BorderLayout());
250+
title.setOpaque(false);
251+
title.setBorder(JBUI.Borders.empty(8, 0));
252+
title.add(new JBLabel(CodeGPTBundle.get("chatMessageResponseBody.webPagesTitle"))
253+
.withFont(JBUI.Fonts.miniFont()), BorderLayout.LINE_START);
254+
panel.add(title);
255+
256+
var listPanel = new JPanel(new BorderLayout());
257+
listPanel.add(webpageList, BorderLayout.LINE_START);
258+
panel.add(listPanel);
259+
260+
return panel;
234261
}
235262
}

0 commit comments

Comments
 (0)