Skip to content

Commit

Permalink
build: ui tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
mmiscool committed Dec 18, 2024
1 parent b1a5ef3 commit e8cdf77
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 35 deletions.
11 changes: 0 additions & 11 deletions .parcelrc

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
53 changes: 31 additions & 22 deletions public/ChatManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -372,7 +372,6 @@ export class ChatManager {
savePlanButton.style.borderRadius = '3px';
savePlanButton.addEventListener('click', async () => {
await doAjax('./savePlan', { plan: message.content });

});
individualMessageDiv.appendChild(savePlanButton);

Expand Down Expand Up @@ -606,15 +605,25 @@ export class ChatManager {
// Query all <code> 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 <code>
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';
Expand Down Expand Up @@ -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 <code> element with the wrapper
const parent = codeElement.parentNode;
Expand All @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion src/intelligentMerge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down

0 comments on commit e8cdf77

Please sign in to comment.