@@ -12,6 +12,7 @@ import { URI, UriComponents } from 'vs/base/common/uri';
1212import * as modes from 'vs/editor/common/modes' ;
1313import { localize } from 'vs/nls' ;
1414import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions' ;
15+ import { IFileService } from 'vs/platform/files/common/files' ;
1516import { IOpenerService } from 'vs/platform/opener/common/opener' ;
1617import { IProductService } from 'vs/platform/product/common/productService' ;
1718import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry' ;
@@ -107,6 +108,7 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma
107108 @IProductService private readonly _productService : IProductService ,
108109 @ITelemetryService private readonly _telemetryService : ITelemetryService ,
109110 @IWebviewWorkbenchService private readonly _webviewWorkbenchService : IWebviewWorkbenchService ,
111+ @IFileService private readonly _fileService : IFileService ,
110112 ) {
111113 super ( ) ;
112114
@@ -319,7 +321,8 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma
319321 this . _customEditorModels . set ( model , { referenceCount : 1 } ) ;
320322
321323 const capabilitiesSet = new Set ( capabilities ) ;
322- if ( capabilitiesSet . has ( extHostProtocol . WebviewEditorCapabilities . Editable ) ) {
324+ const isEditable = capabilitiesSet . has ( extHostProtocol . WebviewEditorCapabilities . Editable ) ;
325+ if ( isEditable ) {
323326 model . onUndo ( edits => {
324327 this . _proxy . $undoEdits ( resource , viewType , edits . map ( x => x . data ) ) ;
325328 } ) ;
@@ -335,10 +338,17 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma
335338 e . waitUntil ( this . _proxy . $onSave ( resource . toJSON ( ) , viewType ) ) ;
336339 } ) ;
337340
338- model . onWillSaveAs ( e => {
339- e . waitUntil ( this . _proxy . $onSaveAs ( e . resource . toJSON ( ) , viewType , e . targetResource . toJSON ( ) ) ) ;
340- } ) ;
341341 }
342+
343+ // Save as should always be implemented even if the model is readonly
344+ model . onWillSaveAs ( e => {
345+ if ( isEditable ) {
346+ e . waitUntil ( this . _proxy . $onSaveAs ( e . resource . toJSON ( ) , viewType , e . targetResource . toJSON ( ) ) ) ;
347+ } else {
348+ // Since the editor is readonly, just copy the file over
349+ e . waitUntil ( this . _fileService . copy ( e . resource , e . targetResource , false /* overwrite */ ) ) ;
350+ }
351+ } ) ;
342352 return model ;
343353 }
344354
0 commit comments