@@ -1436,9 +1436,12 @@ class W3rEditorProvider implements vscode.CustomEditorProvider<W3rDocument> {
14361436 return doc ;
14371437 }
14381438 async resolveCustomEditor ( doc : W3rDocument , panel : vscode . WebviewPanel ) : Promise < void > {
1439- panel . webview . options = { enableScripts : true , localResourceRoots : [ ] } ; doc . webview = panel . webview ;
1440- panel . onDidDispose ( ( ) => { if ( doc . webview === panel . webview ) doc . webview = undefined ; } ) ;
1441- panel . webview . onDidReceiveMessage ( ( message ) => this . handleMessage ( message , doc ) ) ; this . render ( doc , panel . webview ) ;
1439+ const webview = panel . webview ;
1440+ webview . options = { enableScripts : true , localResourceRoots : [ ] } ;
1441+ doc . webview = webview ;
1442+ panel . onDidDispose ( ( ) => { if ( doc . webview === webview ) doc . webview = undefined ; } ) ;
1443+ webview . onDidReceiveMessage ( ( message ) => this . handleMessage ( message , doc ) ) ;
1444+ this . render ( doc , webview ) ;
14421445 }
14431446 private render ( doc : W3rDocument , webview : vscode . Webview ) : void {
14441447 const fileName = doc . uri . path . slice ( doc . uri . path . lastIndexOf ( '/' ) + 1 ) ;
@@ -1461,10 +1464,19 @@ class W3rEditorProvider implements vscode.CustomEditorProvider<W3rDocument> {
14611464 private removeRegion ( doc : W3rDocument , index : number ) : void { const removed = { ...doc . file . regions [ index ] } ; this . pushEdit ( doc , 'Remove region' , { apply : ( ) => { doc . file . regions . splice ( index , 1 ) ; } , revert : ( ) => { doc . file . regions . splice ( index , 0 , removed ) ; } } ) ; }
14621465 private editRegionField ( doc : W3rDocument , index : number , field : string , rawValue : string ) : void {
14631466 const before = { ...doc . file . regions [ index ] } ; const after = { ...before } ;
1464- if ( field === 'name' || field === 'weatherId' || field === 'sound' ) after [ field ] = rawValue ;
1465- else if ( field === 'color' ) { const color = parseMmpColor ( rawValue ) ; if ( ! color ) return ; Object . assign ( after , color ) ; }
1466- else if ( W3R_NUMERIC_FIELDS . has ( field as keyof W3rRegion ) ) { const value = Number ( rawValue ) ; if ( ! Number . isFinite ( value ) || ( field === 'index' && ! Number . isInteger ( value ) ) ) return ; after [ field as keyof W3rRegion ] = value as never ; }
1467- else return ;
1467+ if ( field === 'name' || field === 'weatherId' || field === 'sound' ) {
1468+ after [ field ] = rawValue ;
1469+ } else if ( field === 'color' ) {
1470+ const color = parseMmpColor ( rawValue ) ;
1471+ if ( ! color ) return ;
1472+ Object . assign ( after , color ) ;
1473+ } else if ( W3R_NUMERIC_FIELDS . has ( field as keyof W3rRegion ) ) {
1474+ const value = Number ( rawValue ) ;
1475+ if ( ! Number . isFinite ( value ) || ( field === 'index' && ! Number . isInteger ( value ) ) ) return ;
1476+ after [ field as keyof W3rRegion ] = value as never ;
1477+ } else {
1478+ return ;
1479+ }
14681480 if ( JSON . stringify ( before ) === JSON . stringify ( after ) ) return ;
14691481 this . pushEdit ( doc , `Edit region ${ field } ` , { apply : ( ) => { doc . file . regions [ index ] = { ...after } ; } , revert : ( ) => { doc . file . regions [ index ] = { ...before } ; } } ) ;
14701482 }
@@ -1643,11 +1655,12 @@ class MmpEditorProvider implements vscode.CustomEditorProvider<MmpDocument> {
16431655 }
16441656
16451657 async resolveCustomEditor ( doc : MmpDocument , panel : vscode . WebviewPanel ) : Promise < void > {
1646- panel . webview . options = { enableScripts : true , localResourceRoots : [ ] } ;
1647- doc . webview = panel . webview ;
1648- panel . onDidDispose ( ( ) => { if ( doc . webview === panel . webview ) doc . webview = undefined ; } ) ;
1649- panel . webview . onDidReceiveMessage ( ( message ) => this . handleMessage ( message , doc ) ) ;
1650- this . render ( doc , panel . webview ) ;
1658+ const panelWebview = panel . webview ;
1659+ panelWebview . options = { enableScripts : true , localResourceRoots : [ ] } ;
1660+ doc . webview = panelWebview ;
1661+ panel . onDidDispose ( ( ) => { if ( doc . webview === panelWebview ) doc . webview = undefined ; } ) ;
1662+ panelWebview . onDidReceiveMessage ( ( message ) => this . handleMessage ( message , doc ) ) ;
1663+ this . render ( doc , panelWebview ) ;
16511664 }
16521665
16531666 private render ( doc : MmpDocument , webview : vscode . Webview ) : void {
0 commit comments