@@ -14,44 +14,43 @@ alert('Webview loaded!');
1414 messageDiv . className = `message ${ type } ` ;
1515
1616 if ( isCode ) {
17+ // Detect file creation pattern
18+ const fileMatch = content . match ( / ^ F i l e n a m e : \s * ( \S + ) \s * \n ( [ \s \S ] * ) / ) ;
1719 const pre = document . createElement ( 'pre' ) ;
1820 const code = document . createElement ( 'code' ) ;
1921 code . textContent = content ;
2022 pre . appendChild ( code ) ;
2123 messageDiv . appendChild ( pre ) ;
22-
23- // Add action buttons for code
24- const actionsDiv = document . createElement ( 'div' ) ;
25- actionsDiv . className = 'code-actions' ;
26-
27- const insertBtn = document . createElement ( 'button' ) ;
28- insertBtn . textContent = 'Insert at Cursor' ;
29- insertBtn . onclick = ( ) => {
30- vscode . postMessage ( {
31- type : 'insertCode' ,
32- code : content
33- } ) ;
34- } ;
35-
36- const replaceBtn = document . createElement ( 'button' ) ;
37- replaceBtn . textContent = 'Replace Selection' ;
38- replaceBtn . onclick = ( ) => {
39- vscode . postMessage ( {
40- type : 'replaceCode' ,
41- code : content
42- } ) ;
43- } ;
44-
45- const copyBtn = document . createElement ( 'button' ) ;
46- copyBtn . textContent = 'Copy' ;
47- copyBtn . onclick = ( ) => {
48- navigator . clipboard . writeText ( content ) ;
49- } ;
50-
51- actionsDiv . appendChild ( insertBtn ) ;
52- actionsDiv . appendChild ( replaceBtn ) ;
53- actionsDiv . appendChild ( copyBtn ) ;
54- messageDiv . appendChild ( actionsDiv ) ;
24+ if ( ! fileMatch ) {
25+ // Add action buttons for code (not for file creation)
26+ const actionsDiv = document . createElement ( 'div' ) ;
27+ actionsDiv . className = 'code-actions' ;
28+ const insertBtn = document . createElement ( 'button' ) ;
29+ insertBtn . textContent = 'Insert at Cursor' ;
30+ insertBtn . onclick = ( ) => {
31+ vscode . postMessage ( {
32+ type : 'insertCode' ,
33+ code : content
34+ } ) ;
35+ } ;
36+ const replaceBtn = document . createElement ( 'button' ) ;
37+ replaceBtn . textContent = 'Replace Selection' ;
38+ replaceBtn . onclick = ( ) => {
39+ vscode . postMessage ( {
40+ type : 'replaceCode' ,
41+ code : content
42+ } ) ;
43+ } ;
44+ const copyBtn = document . createElement ( 'button' ) ;
45+ copyBtn . textContent = 'Copy' ;
46+ copyBtn . onclick = ( ) => {
47+ navigator . clipboard . writeText ( content ) ;
48+ } ;
49+ actionsDiv . appendChild ( insertBtn ) ;
50+ actionsDiv . appendChild ( replaceBtn ) ;
51+ actionsDiv . appendChild ( copyBtn ) ;
52+ messageDiv . appendChild ( actionsDiv ) ;
53+ }
5554 } else {
5655 // Format text with markdown-like support
5756 const formattedContent = formatText ( content ) ;
0 commit comments