From e8cdf7715ba1e8eca92177cbe271bc7ac01c896c Mon Sep 17 00:00:00 2001 From: mmiscool Date: Tue, 17 Dec 2024 21:33:28 -0500 Subject: [PATCH] build: ui tweaks --- .parcelrc | 11 --------- package.json | 2 +- public/ChatManager.js | 53 ++++++++++++++++++++++++----------------- src/intelligentMerge.js | 2 +- 4 files changed, 33 insertions(+), 35 deletions(-) delete mode 100644 .parcelrc diff --git a/.parcelrc b/.parcelrc deleted file mode 100644 index a59fe92..0000000 --- a/.parcelrc +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "@parcel/config-default", - "transformers": { - "*.{js,jsx,ts,tsx}": ["@parcel/transformer-js"] - }, - "bundler": "@parcel/bundler-default", - "packagers": { - "*.js": "@parcel/packager-js" - }, - "reporters": ["@parcel/reporter-cli"] -} diff --git a/package.json b/package.json index ca412eb..6c3f409 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ }, "scripts": { "start": "./src/main.js", - "buildFrontend": " ./node_modules/.bin/parcel watch ./public/index.html --no-hmr " + "buildFrontend": " ./node_modules/.bin/parcel watch ./public/index.html --no-hmr" }, "targets": { "default": { diff --git a/public/ChatManager.js b/public/ChatManager.js index fe76d83..5222b77 100644 --- a/public/ChatManager.js +++ b/public/ChatManager.js @@ -358,10 +358,10 @@ export class ChatManager { const contentDiv = document.createElement('div'); - const markdown = new MarkdownToHtml(contentDiv, message.content); + const markdown = await new MarkdownToHtml(contentDiv, message.content); individualMessageDiv.appendChild(contentDiv); - if (this.chatMode === 'plan' && message.role === 'assistant') { + if (message.role === 'assistant') { const savePlanButton = document.createElement('button'); savePlanButton.textContent = '💾 Replace plan' savePlanButton.style.cursor = 'pointer'; @@ -372,7 +372,6 @@ export class ChatManager { savePlanButton.style.borderRadius = '3px'; savePlanButton.addEventListener('click', async () => { await doAjax('./savePlan', { plan: message.content }); - }); individualMessageDiv.appendChild(savePlanButton); @@ -606,15 +605,25 @@ export class ChatManager { // Query all elements on the page let codeElements = []; - // gather all elements that have the "language-javascript" class - if (this.chatMode === 'plan') codeElements = await document.querySelectorAll('.language-markdown'); - if (this.chatMode === 'chat') codeElements = await document.querySelectorAll('.language-javascript'); + // querySelector for all elements of type + if (this.chatMode === 'plan') codeElements = await document.getElementsByTagName('code'); + + if (this.chatMode === 'chat') { + codeElements = await document.getElementsByTagName('code'); + // filter out the code elements that are a single line + codeElements = Array.from(codeElements).filter((codeElement) => { + return codeElement.textContent.split('\n').length > 1; + }); + } + - //console.log('codeElements', codeElements); + codeElements = Array.from(codeElements); + console.log('codeElements', codeElements); if (codeElements.length === 0) return; codeElements.forEach((codeElement) => { + console.log('codeElement', codeElement); // Create a wrapper to hold the code and toolbar const wrapper = document.createElement('div'); wrapper.style.position = 'relative'; @@ -655,21 +664,21 @@ export class ChatManager { }); toolbar.appendChild(copyButton); - if (this.chatMode === 'chat') { - const editButton = document.createElement('button'); - editButton.textContent = '🤖✎⚡'; - editButton.title = 'Apply snippet'; - Object.assign(editButton.style, buttonStyles); - editButton.addEventListener('click', async () => { - codeElement.style.color = 'red'; - const codeString = codeElement.textContent; - await this.applySnippet(codeString); - codeElement.style.color = 'cyan'; - ctx.tools.displayListOfStubsAndMethods(); - }); - toolbar.appendChild(editButton); - } + const editButton = document.createElement('button'); + editButton.textContent = '🤖✎⚡'; + editButton.title = 'Apply snippet'; + Object.assign(editButton.style, buttonStyles); + editButton.addEventListener('click', async () => { + codeElement.style.color = 'red'; + const codeString = codeElement.textContent; + await this.applySnippet(codeString); + codeElement.style.color = 'cyan'; + ctx.tools.displayListOfStubsAndMethods(); + }); + + toolbar.appendChild(editButton); + // Wrap the element with the wrapper const parent = codeElement.parentNode; @@ -686,7 +695,7 @@ export class ChatManager { const isCodeGood = await doAjax('./applySnippet', { snippet: codeString, targetFile: this.targetFileInput.value }); if (!isCodeGood.success) { - await alert('Merge failed. Please resolve the conflict manually.'); + await alert('Merge failed. Please resolve the conflict manually.'); // set the user input to say that the snippet was formatted incorrectly // and needs to be corrected. diff --git a/src/intelligentMerge.js b/src/intelligentMerge.js index aef6d5f..846dffb 100644 --- a/src/intelligentMerge.js +++ b/src/intelligentMerge.js @@ -316,7 +316,7 @@ export class codeManipulator { // Wrap with block comment syntax, ensuring proper formatting const formattedBlockComment = `\n${indent}*\n${formattedComment}\n${indent}*`; - console.log(formattedBlockComment); + //console.log(formattedBlockComment); // Replace leadingComments with the correctly formatted single block comment node.leadingComments = [ {