Skip to content

Commit

Permalink
fix: avoid resetting last unsent user prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
Francesco Piccoli committed Dec 9, 2024
1 parent 429064b commit d27d0a6
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions src/components/chat-item/chat-prompt-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class ChatPromptInput {
private selectedCommand: string = '';
private readonly userPromptHistory: UserPrompt[] = [];
private userPromptHistoryIndex: number = -1;
private lastUnsentUserPrompt: UserPrompt;
constructor (props: ChatPromptInputProps) {
this.props = props;
this.promptTextInputCommand = new ChatPromptInputCommand({
Expand Down Expand Up @@ -323,6 +324,13 @@ export class ChatPromptInput {
this.quickPickOpen = true;
}
} else if (navigationalKeys.includes(e.key)) {
if (this.userPromptHistoryIndex === -1 || this.userPromptHistoryIndex === this.userPromptHistory.length) {
this.lastUnsentUserPrompt = {
inputText: this.promptTextInput.getTextInputValue(),
codeAttachment: this.promptAttachment?.lastAttachmentContent ?? '',
};
}

this.clearTextArea();

if (this.userPromptHistoryIndex === -1) {
Expand All @@ -335,22 +343,24 @@ export class ChatPromptInput {
this.userPromptHistoryIndex = Math.min(this.userPromptHistory.length, this.userPromptHistoryIndex + 1);
}

let codeAttachment = '';
if (this.userPromptHistoryIndex === this.userPromptHistory.length) {
MynahUITabsStore.getInstance().getTabDataStore(this.props.tabId).updateStore({
promptInputText: '',
promptInputText: this.lastUnsentUserPrompt.inputText,
});
codeAttachment = this.lastUnsentUserPrompt.codeAttachment;
} else {
MynahUITabsStore.getInstance().getTabDataStore(this.props.tabId).updateStore({
promptInputText: this.userPromptHistory[this.userPromptHistoryIndex].inputText,
});
let codeAttachment = this.userPromptHistory[this.userPromptHistoryIndex].codeAttachment;
if (typeof codeAttachment === 'string' && codeAttachment.trim().length > 0) {
codeAttachment = codeAttachment
.replace(/~~~~~~~~~~/, '')
.replace(/~~~~~~~~~~$/, '')
.trim();
this.addAttachment(codeAttachment, 'code');
}
codeAttachment = this.userPromptHistory[this.userPromptHistoryIndex].codeAttachment;
}
if (codeAttachment.trim().length > 0) {
codeAttachment = codeAttachment
.replace(/~~~~~~~~~~/, '')
.replace(/~~~~~~~~~~$/, '')
.trim();
this.addAttachment(codeAttachment, 'code');
}
}
} else {
Expand Down Expand Up @@ -675,9 +685,15 @@ export class ChatPromptInput {
if (currentInputValue !== '') {
this.userPromptHistory.push({
inputText: currentInputValue,
codeAttachment: attachmentContent,
codeAttachment: attachmentContent ?? '',
});
}

this.lastUnsentUserPrompt = {
inputText: '',
codeAttachment: '',
};

this.userPromptHistoryIndex = -1;
MynahUIGlobalEvents.getInstance().dispatch(MynahEventNames.CHAT_PROMPT, promptData);
}
Expand Down

0 comments on commit d27d0a6

Please sign in to comment.