From e1180b210b6bf2031bfe02263be83998b04adfb5 Mon Sep 17 00:00:00 2001 From: michaelangeloio Date: Tue, 6 Aug 2024 21:08:53 -0400 Subject: [PATCH 01/33] save --- .../experimental/duo/chat/duo_chat.vue | 95 ++++++++++-- .../duo/chat/duo_chat_include.vue | 139 ++++++++++++++++++ .../experimental/duo/chat/mock_data.js | 4 + 3 files changed, 226 insertions(+), 12 deletions(-) create mode 100644 src/components/experimental/duo/chat/duo_chat_include.vue diff --git a/src/components/experimental/duo/chat/duo_chat.vue b/src/components/experimental/duo/chat/duo_chat.vue index 1dc3cdba13..6fe7d44a35 100644 --- a/src/components/experimental/duo/chat/duo_chat.vue +++ b/src/components/experimental/duo/chat/duo_chat.vue @@ -16,6 +16,7 @@ import { SafeHtmlDirective as SafeHtml } from '../../../../directives/safe_html/ import GlDuoChatLoader from './components/duo_chat_loader/duo_chat_loader.vue'; import GlDuoChatPredefinedPrompts from './components/duo_chat_predefined_prompts/duo_chat_predefined_prompts.vue'; import GlDuoChatConversation from './components/duo_chat_conversation/duo_chat_conversation.vue'; +import GlDuoChatInclude from './duo_chat_include.vue'; import { CHAT_CLEAN_MESSAGE, CHAT_RESET_MESSAGE, CHAT_CLEAR_MESSAGE } from './constants'; export const i18n = { @@ -62,6 +63,7 @@ export default { GlDuoChatConversation, GlCard, GlDropdownItem, + GlDuoChatInclude, }, directives: { SafeHtml, @@ -207,6 +209,9 @@ export default { activeCommandIndex: 0, displaySubmitButton: true, compositionJustEnded: false, + showIncludeDropdown: false, + cursorPosition: 0, + selectedIncludes: [] }; }, computed: { @@ -363,6 +368,7 @@ export default { return !(isModifierKey || isComposing || this.compositionJustEnded); }, onInputKeyup(e) { + console.log('shayon testing', e?.key); const { key } = e; if (this.shouldShowSlashCommands) { @@ -412,11 +418,45 @@ export default { this.sendChatPrompt(); } else { this.setPromptAndFocus(`${command.name} `); + if (command.name === '/include') { + console.log('including dropdown'); + this.showIncludeDropdown = true; + } } }, onInsertCodeSnippet(e) { this.$emit('insert-code-snippet', e); }, + handleFileSelected(file) { + // Handle the selected file (e.g., add to context, update UI, etc.) + }, + handleIncludeRemoved(include) { + // Handle the removed include (e.g., remove from context, update UI, etc.) + }, + + updateCursorPosition() { + const textArea = this.$refs.prompt.$el; + const cursorPosition = textArea.selectionStart; + const textBeforeCursor = this.prompt.substring(0, cursorPosition); + const textWidth = this.getTextWidth(textBeforeCursor, getComputedStyle(textArea)); + this.cursorPosition = textWidth; + }, + getTextWidth(text, style) { + const canvas = document.createElement('canvas'); + const context = canvas.getContext('2d'); + context.font = `${style.fontSize} ${style.fontFamily}`; + return context.measureText(text).width; + }, + handleItemSelected(item) { + this.selectedIncludes.push(item); + this.prompt = this.prompt.replace('/include', '').trim(); + this.$nextTick(() => { + this.$refs.prompt.$el.focus(); + }); + }, + removeInclude(include) { + this.selectedIncludes = this.selectedIncludes.filter((i) => i.id !== include.id); + }, }, i18n, emptySvg, @@ -532,6 +572,18 @@ export default { :class="{ 'duo-chat-drawer-body-scrim-on-footer': !scrolledToBottom }" > +
+ + {{ include.name }} + × + +
+
+ - + +
+ diff --git a/src/components/experimental/duo/chat/duo_chat_include.vue b/src/components/experimental/duo/chat/duo_chat_include.vue new file mode 100644 index 0000000000..631e09013a --- /dev/null +++ b/src/components/experimental/duo/chat/duo_chat_include.vue @@ -0,0 +1,139 @@ + + + + + diff --git a/src/components/experimental/duo/chat/mock_data.js b/src/components/experimental/duo/chat/mock_data.js index ae45a12ea7..1968ef30dd 100644 --- a/src/components/experimental/duo/chat/mock_data.js +++ b/src/components/experimental/duo/chat/mock_data.js @@ -165,4 +165,8 @@ export const SLASH_COMMANDS = [ name: '/explain', description: 'Explain the selected snippet.', }, + { + name: '/include', + description: 'Add context to your chat.' + } ]; -- GitLab From d20141080d9ff6b59bd2d6f9aed79578cfe45a06 Mon Sep 17 00:00:00 2001 From: michaelangeloio Date: Wed, 7 Aug 2024 12:05:13 -0400 Subject: [PATCH 02/33] save --- .../experimental/duo/chat/duo_chat.vue | 5 - .../duo/chat/duo_chat_include.vue | 116 +++++++++--------- 2 files changed, 61 insertions(+), 60 deletions(-) diff --git a/src/components/experimental/duo/chat/duo_chat.vue b/src/components/experimental/duo/chat/duo_chat.vue index 6fe7d44a35..a82c74a0b8 100644 --- a/src/components/experimental/duo/chat/duo_chat.vue +++ b/src/components/experimental/duo/chat/duo_chat.vue @@ -610,10 +610,6 @@ export default { -
-