File tree Expand file tree Collapse file tree 2 files changed +25
-8
lines changed Expand file tree Collapse file tree 2 files changed +25
-8
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ function activate(context) {
2626 panel . webview . postMessage ( {
2727 type : 'restore' ,
2828 innerHTML : state . innerHTML ,
29+ bgColor : context . globalState . get ( 'polacode.bgColor' , '#2e3440' )
2930 } )
3031 }
3132 } )
@@ -55,6 +56,12 @@ function activate(context) {
5556 }
5657 } )
5758 break
59+ case 'getAndUpdateBgColor' :
60+ panel . webview . postMessage ( {
61+ type : 'restoreBgColor' ,
62+ bgColor : context . globalState . get ( 'polacode.bgColor' , '#2e3440' )
63+ } )
64+ break
5865 case 'updateBgColor' :
5966 context . globalState . update ( 'polacode.bgColor' , data . bgColor )
6067 break
Original file line number Diff line number Diff line change 11; ( function ( ) {
22 const vscode = acquireVsCodeApi ( )
33
4+ vscode . postMessage ( {
5+ type : 'getAndUpdateBgColor'
6+ } )
7+
48 const snippetNode = document . getElementById ( 'snippet' )
59 const snippetContainerNode = document . getElementById ( 'snippet-container' )
610 const obturateur = document . getElementById ( 'save' )
5256 return getBrightness ( hexColor ) < 128
5357 }
5458 function getSnippetBgColor ( html ) {
55- return html . match ( / b a c k g r o u n d - c o l o r : ( # [ a - f A - F 0 - 9 ] + ) / ) [ 1 ]
59+ const match = html . match ( / b a c k g r o u n d - c o l o r : ( # [ a - f A - F 0 - 9 ] + ) / )
60+ return match [ 1 ] ? match [ 1 ] : undefined ;
5661 }
5762
5863 function updateEnvironment ( snippetBgColor ) {
99104 const minIndent = getMinIndent ( code )
100105
101106 const snippetBgColor = getSnippetBgColor ( innerHTML )
102- vscode . postMessage ( {
103- type : 'updateBgColor' ,
104- data : {
105- bgColor : snippetBgColor
106- }
107- } )
108- updateEnvironment ( snippetBgColor )
107+ if ( snippetBgColor ) {
108+ vscode . postMessage ( {
109+ type : 'updateBgColor' ,
110+ data : {
111+ bgColor : snippetBgColor
112+ }
113+ } )
114+ updateEnvironment ( snippetBgColor )
115+ }
109116
110117 if ( minIndent !== 0 ) {
111118 snippetNode . innerHTML = stripInitialIndent ( innerHTML , minIndent )
180187 document . execCommand ( 'paste' )
181188 } else if ( e . data . type === 'restore' ) {
182189 snippetNode . innerHTML = e . data . innerHTML
190+ updateEnvironment ( e . data . bgColor )
191+ } else if ( e . data . type === 'restoreBgColor' ) {
192+ updateEnvironment ( e . data . bgColor )
183193 }
184194 }
185195 } )
You can’t perform that action at this time.
0 commit comments