Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #356 #357

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.devoxx.genie.service.ChatPromptExecutor;
import com.devoxx.genie.service.DevoxxGenieSettingsService;
import com.devoxx.genie.ui.EditorFileButtonManager;
import com.devoxx.genie.ui.component.PromptInputArea;
import com.devoxx.genie.ui.component.input.PromptInputArea;
import com.devoxx.genie.ui.panel.ActionButtonsPanel;
import com.devoxx.genie.ui.panel.PromptOutputPanel;
import com.devoxx.genie.ui.settings.DevoxxGenieStateService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.devoxx.genie.model.request.EditorInfo;
import com.devoxx.genie.service.streaming.StreamingPromptExecutor;
import com.devoxx.genie.service.websearch.WebSearchExecutor;
import com.devoxx.genie.ui.component.PromptInputArea;
import com.devoxx.genie.ui.component.input.PromptInputArea;
import com.devoxx.genie.ui.panel.PromptOutputPanel;
import com.devoxx.genie.ui.settings.DevoxxGenieStateService;
import com.devoxx.genie.ui.util.NotificationUtil;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.devoxx.genie.ui.component;
package com.devoxx.genie.ui.component.input;

import com.devoxx.genie.model.CustomPrompt;
import com.devoxx.genie.service.DevoxxGenieSettingsService;
Expand All @@ -25,7 +25,7 @@ public class CommandAutoCompleteTextField extends JBTextArea implements CustomPr
private static final Logger LOG = Logger.getInstance(CommandAutoCompleteTextField.class);

private final List<String> commands = new ArrayList<>();
private final Project project;
private final transient Project project;

private boolean isAutoCompleting = false;
private String placeholder = "";
Expand Down Expand Up @@ -69,35 +69,35 @@ public void keyPressed(@NotNull KeyEvent e) {
e.consume();
}
}
}

private void sendPrompt() {
String text = getText().trim();
if (!text.isEmpty()) {
ApplicationManager.getApplication().getMessageBus()
.syncPublisher(AppTopics.PROMPT_SUBMISSION_TOPIC)
.onPromptSubmitted(project, text);
private void sendPrompt() {
String text = getText().trim();
if (!text.isEmpty()) {
ApplicationManager.getApplication().getMessageBus()
.syncPublisher(AppTopics.PROMPT_SUBMISSION_TOPIC)
.onPromptSubmitted(project, text);
}
}
}

private void autoComplete() {
String text = getText();
String[] lines = text.split("\n");
if (lines.length > 0 && lines[lines.length - 1].startsWith("/")) {
String currentLine = lines[lines.length - 1];
for (String command : commands) {
if (command.startsWith(currentLine)) {
isAutoCompleting = true;
int start = text.lastIndexOf("\n") + 1;
try {
getDocument().remove(start, currentLine.length());
getDocument().insertString(start, command, null);
} catch (BadLocationException ex) {
LOG.error("Error while auto-completing command", ex);
private void autoComplete() {
String text = getText();
String[] lines = text.split("\n");
if (lines.length > 0 && lines[lines.length - 1].startsWith("/")) {
String currentLine = lines[lines.length - 1];
for (String command : commands) {
if (command.startsWith(currentLine)) {
isAutoCompleting = true;
int start = text.lastIndexOf("\n") + 1;
try {
getDocument().remove(start, currentLine.length());
getDocument().insertString(start, command, null);
} catch (BadLocationException ex) {
LOG.error("Error while auto-completing command", ex);
}
setCaretPosition(text.length() - currentLine.length() + command.length());
isAutoCompleting = false;
break;
}
setCaretPosition(text.length() - currentLine.length() + command.length());
isAutoCompleting = false;
break;
}
}
}
Expand All @@ -112,39 +112,63 @@ public void insertString(int offs, String str, AttributeSet a) throws BadLocatio
}

super.insertString(offs, str, a);
scheduleAutoComplete();
}

private void scheduleAutoComplete() {
ApplicationManager.getApplication().invokeLater(() -> {
try {
String text = getText(0, getLength());
String[] lines = text.split("\n");
if (lines.length > 0) {
String currentLine = lines[lines.length - 1];
if (currentLine.startsWith("/") && currentLine.length() > 1) {
for (String command : commands) {
if (command.startsWith(currentLine) && !command.equals(currentLine)) {
String completion = command.substring(currentLine.length());
isAutoCompleting = true;
insertString(getLength(), completion, null);
setCaretPosition(getLength());
moveCaretPosition(getLength() - completion.length());
isAutoCompleting = false;
break;
}
}
}
}
handleAutoComplete();
} catch (BadLocationException e) {
LOG.error("Error while auto-completing command", e);
}
});
}

private void handleAutoComplete() throws BadLocationException {
String text = getText(0, getLength());
String currentLine = getCurrentLine(text);

if (shouldAttemptAutoComplete(currentLine)) {
attemptAutoComplete(currentLine);
}
}

private String getCurrentLine(@NotNull String text) {
String[] lines = text.split("\n");
return lines.length > 0 ? lines[lines.length - 1] : "";
}

private boolean shouldAttemptAutoComplete(@NotNull String currentLine) {
return currentLine.startsWith("/") && currentLine.length() > 1;
}

private void attemptAutoComplete(String currentLine) throws BadLocationException {
for (String command : commands) {
if (command.startsWith(currentLine) && !command.equals(currentLine)) {
applyAutoComplete(command, currentLine);
break;
}
}
}

private void applyAutoComplete(@NotNull String command,
@NotNull String currentLine) throws BadLocationException {
String completion = command.substring(currentLine.length());
isAutoCompleting = true;
insertString(getLength(), completion, null);
setCaretPosition(getLength());
moveCaretPosition(getLength() - completion.length());
isAutoCompleting = false;
}
}

public void setPlaceholder(String placeholder) {
this.placeholder = placeholder;
repaint();
}

@Override
public void onCustomPromptsChanged() {
initializeCommands();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.devoxx.genie.ui.component;
package com.devoxx.genie.ui.component.input;

import com.devoxx.genie.ui.component.GlowingBorder;
import com.devoxx.genie.ui.listener.PromptInputFocusListener;
import com.devoxx.genie.ui.panel.SearchOptionsPanel;
import com.intellij.openapi.application.ApplicationManager;
Expand Down Expand Up @@ -31,17 +32,7 @@ public PromptInputArea(@NotNull ResourceBundle resourceBundle, Project project)
inputField.addFocusListener(new PromptInputFocusListener(inputField));
inputField.setPlaceholder(resourceBundle.getString("prompt.placeholder"));

// Set minimum size for 2 lines
FontMetrics fontMetrics = inputField.getFontMetrics(inputField.getFont());
int lineHeight = fontMetrics.getHeight();
int minHeight = (lineHeight * 3) +
inputField.getInsets().top +
inputField.getInsets().bottom +
10; // Additional padding

Dimension minimumSize = new Dimension(0, minHeight);
inputField.setMinimumSize(minimumSize);
inputField.setPreferredSize(minimumSize);
inputField.setRows(3);

glowingBorder = new GlowingBorder(new JBColor(new Color(0, 120, 215), new Color(0, 120, 213)));
setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
Expand All @@ -52,7 +43,11 @@ public PromptInputArea(@NotNull ResourceBundle resourceBundle, Project project)

add(inputAreaPanel, BorderLayout.CENTER);

glowTimer = new Timer(50, new ActionListener() {
glowTimer = getGlowTimer();
}

private Timer getGlowTimer() {
return new Timer(50, new ActionListener() {
private float direction = 0.05f;

@Override
Expand Down Expand Up @@ -101,10 +96,12 @@ public void clear() {
inputField.setText("");
}

@Override
public void setEnabled(boolean enabled) {
inputField.setEnabled(enabled);
}

@Override
public boolean requestFocusInWindow() {
return inputField.requestFocusInWindow();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.devoxx.genie.ui.EditorFileButtonManager;
import com.devoxx.genie.ui.component.ContextPopupMenu;
import com.devoxx.genie.ui.component.JHoverButton;
import com.devoxx.genie.ui.component.PromptInputArea;
import com.devoxx.genie.ui.component.input.PromptInputArea;
import com.devoxx.genie.ui.component.TokenUsageBar;
import com.devoxx.genie.ui.listener.PromptSubmissionListener;
import com.devoxx.genie.ui.listener.SettingsChangeListener;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/devoxx/genie/ui/panel/SubmitPanel.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.devoxx.genie.ui.panel;

import com.devoxx.genie.ui.DevoxxGenieToolWindowContent;
import com.devoxx.genie.ui.component.PromptInputArea;
import com.devoxx.genie.ui.component.input.PromptInputArea;
import com.intellij.openapi.project.Project;
import com.intellij.ui.components.JBPanel;
import com.intellij.ui.components.JBScrollPane;
Expand Down Expand Up @@ -39,8 +39,9 @@ public SubmitPanel(DevoxxGenieToolWindowContent toolWindowContent)
promptInputArea = new PromptInputArea(resourceBundle, project);

JPanel submitPanel = new JPanel(new BorderLayout());
submitPanel.setMinimumSize(new Dimension(Integer.MAX_VALUE, MIN_INPUT_HEIGHT));
submitPanel.setMinimumSize(new Dimension(0, MIN_INPUT_HEIGHT));
submitPanel.setPreferredSize(new Dimension(Integer.MAX_VALUE, MIN_INPUT_HEIGHT));

submitPanel.add(promptContextFileListPanel, BorderLayout.NORTH);
submitPanel.add(new JBScrollPane(promptInputArea), BorderLayout.CENTER);
submitPanel.add(createActionButtonsPanel(), BorderLayout.SOUTH);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<UL>
<LI>Fix #352 : Restore horizontal scrolling in chat response panel</LI>
<LI>Fix #354 : Fix splitter proportion for chat window</LI>
<LI>Fix #356 : Fix PromptInputArea scrolling of text</LI>
</UL>
<h2>v0.4.0</h2>
<UL>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Mon Dec 09 19:37:25 CET 2024
#Tue Dec 10 09:10:31 CET 2024
version=0.4.1
Loading