@@ -177,12 +177,11 @@ const LINE_HEIGHT = 36;
177177 ` ;
178178 button . title = "Copy to Clipboard" ;
179179 button . classList . add (
180- "sidebar__chat-assistant--chat-bubble-text--code-copy -button"
180+ "sidebar__chat-assistant--chat-bubble-text--code-action -button"
181181 ) ;
182- block . appendChild ( button ) ;
183182 button . onclick = async ( ) => {
184183 await navigator . clipboard . writeText ( text ) ;
185- button . innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" class="sidebar__chat-assistant--code-block-action-button-icon"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. --><path d="M438.6 105.4c12.5 12.5 12.5 32.8 0 45.3l-256 256c-12.5 12.5-32.8 12.5-45.3 0l-128-128c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 338.7 393.4 105.4c12.5-12.5 32.8-12.5 45.3 0z"/></svg>` ;
184+ button . innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="sidebar__chat-assistant--code-block-action-button-icon"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. --><path d="M438.6 105.4c12.5 12.5 12.5 32.8 0 45.3l-256 256c-12.5 12.5-32.8 12.5-45.3 0l-128-128c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 338.7 393.4 105.4c12.5-12.5 32.8-12.5 45.3 0z"/></svg>` ;
186185 } ;
187186 button . onblur = async ( ) => {
188187 button . innerHTML = `
@@ -195,9 +194,37 @@ const LINE_HEIGHT = 36;
195194 </svg>
196195 ` ;
197196 } ;
197+ return button ;
198198 }
199199 } ;
200200
201+ const setupReplaceButton = ( block ) => {
202+ let text = block . querySelector ( "code" ) . innerText ;
203+ let button = document . createElement ( "button" ) ;
204+ button . innerHTML = `
205+ <svg xmlns="http://www.w3.org/2000/svg" class="sidebar__chat-assistant--code-block-action-button-icon" viewBox="0 0 512 512"><path d="M416 448h-84c-6.6 0-12-5.4-12-12v-40c0-6.6 5.4-12 12-12h84c17.7 0 32-14.3 32-32V160c0-17.7-14.3-32-32-32h-84c-6.6 0-12-5.4-12-12V76c0-6.6 5.4-12 12-12h84c53 0 96 43 96 96v192c0 53-43 96-96 96zm-47-201L201 79c-15-15-41-4.5-41 17v96H24c-13.3 0-24 10.7-24 24v96c0 13.3 10.7 24 24 24h136v96c0 21.5 26 32 41 17l168-168c9.3-9.4 9.3-24.6 0-34z"/></svg>
206+ ` ;
207+ button . title = "Insert code at cursor" ;
208+ button . classList . add (
209+ "sidebar__chat-assistant--chat-bubble-text--code-action-button"
210+ ) ;
211+ button . onclick = async ( ) => {
212+ vscode . postMessage ( { type : "insert_at_cursor" , content : text } ) ;
213+ } ;
214+ return button ;
215+ } ;
216+
217+ const setupActionButtons = ( block ) => {
218+ let buttonGroup = document . createElement ( "div" ) ;
219+ buttonGroup . classList . add (
220+ "sidebar__chat-assistant--chat-bubble-text--code-action-buttons"
221+ ) ;
222+ let copyButton = setupCopyButton ( block ) ;
223+ let replaceButton = setupReplaceButton ( block ) ;
224+ buttonGroup . append ( copyButton , replaceButton ) ;
225+ block . appendChild ( buttonGroup ) ;
226+ } ;
227+
201228 // Function to add an assistant message or add to the existing one
202229 function addAssistantMessageToUI ( message ) {
203230 cancelButton . disabled = false ;
@@ -210,7 +237,7 @@ const LINE_HEIGHT = 36;
210237 currentAssistantMessage . innerHTML = message . textContent ;
211238
212239 let blocks = currentAssistantMessage . querySelectorAll ( "pre" ) ;
213- blocks . forEach ( setupCopyButton ) ;
240+ blocks . forEach ( setupActionButtons ) ;
214241
215242 let httpLinks =
216243 currentAssistantMessage . querySelectorAll ( 'a[href*="http"]' ) ;
0 commit comments