@@ -44,6 +44,8 @@ import { IContextKeyService } from '@theia/monaco-editor-core/esm/vs/platform/co
4444import { ITextModelService } from '@theia/monaco-editor-core/esm/vs/editor/common/services/resolverService' ;
4545import { IReference } from '@theia/monaco-editor-core/esm/vs/base/common/lifecycle' ;
4646import { MarkdownString } from '@theia/core/lib/common/markdown-rendering' ;
47+ import { SimpleMonacoEditor } from './simple-monaco-editor' ;
48+ import { ICodeEditorWidgetOptions } from '@theia/monaco-editor-core/esm/vs/editor/browser/widget/codeEditor/codeEditorWidget' ;
4749
4850export const MonacoEditorFactory = Symbol ( 'MonacoEditorFactory' ) ;
4951export interface MonacoEditorFactory {
@@ -108,9 +110,9 @@ export class MonacoEditorProvider {
108110 return this . doCreateEditor ( uri , ( override , toDispose ) => this . createEditor ( uri , override , toDispose ) ) ;
109111 }
110112
111- protected async doCreateEditor ( uri : URI , factory : (
112- override : EditorServiceOverrides , toDispose : DisposableCollection ) => Promise < MonacoEditor >
113- ) : Promise < MonacoEditor > {
113+ protected async doCreateEditor < T > ( uri : URI , factory : (
114+ override : EditorServiceOverrides , toDispose : DisposableCollection ) => Promise < T >
115+ ) : Promise < T > {
114116 const domNode = document . createElement ( 'div' ) ;
115117 const contextKeyService = StandaloneServices . get ( IContextKeyService ) . createScoped ( domNode ) ;
116118 StandaloneServices . get ( IOpenerService ) . registerOpener ( {
@@ -121,21 +123,22 @@ export class MonacoEditorProvider {
121123 ] ;
122124 const toDispose = new DisposableCollection ( ) ;
123125 const editor = await factory ( overrides , toDispose ) ;
124- editor . onDispose ( ( ) => toDispose . dispose ( ) ) ;
125-
126- this . injectKeybindingResolver ( editor ) ;
127-
128- toDispose . push ( editor . onFocusChanged ( focused => {
129- if ( focused ) {
130- this . _current = editor ;
131- }
132- } ) ) ;
133- toDispose . push ( Disposable . create ( ( ) => {
134- if ( this . _current === editor ) {
135- this . _current = undefined ;
136- }
137- } ) ) ;
138-
126+ if ( editor instanceof MonacoEditor ) {
127+ editor . onDispose ( ( ) => toDispose . dispose ( ) ) ;
128+
129+ this . injectKeybindingResolver ( editor ) ;
130+
131+ toDispose . push ( editor . onFocusChanged ( focused => {
132+ if ( focused ) {
133+ this . _current = editor ;
134+ }
135+ } ) ) ;
136+ toDispose . push ( Disposable . create ( ( ) => {
137+ if ( this . _current === editor ) {
138+ this . _current = undefined ;
139+ }
140+ } ) ) ;
141+ }
139142 return editor ;
140143 }
141144
@@ -369,6 +372,11 @@ export class MonacoEditorProvider {
369372 return MonacoDiffNavigatorFactory . nullNavigator ;
370373 }
371374
375+ /**
376+ * Creates an instance of the standard MonacoEditor with a StandaloneCodeEditor as its Monaco delegeate.
377+ * Among other differences, these editors execute basic actions like typing or deletion via commands that may be overridden by extensions.
378+ * @deprecated Most use cases for inline editors should be served by `createSimpleInline` instead.
379+ */
372380 async createInline ( uri : URI , node : HTMLElement , options ?: MonacoEditor . IOptions ) : Promise < MonacoEditor > {
373381 return this . doCreateEditor ( uri , async ( override , toDispose ) => {
374382 const overrides = override ? Array . from ( override ) : [ ] ;
@@ -383,7 +391,6 @@ export class MonacoEditorProvider {
383391 this . services ,
384392 Object . assign ( {
385393 model,
386- isSimpleWidget : true ,
387394 autoSizing : false ,
388395 minHeight : 1 ,
389396 maxHeight : 1
@@ -393,6 +400,42 @@ export class MonacoEditorProvider {
393400 } ) ;
394401 }
395402
403+ /**
404+ * Creates an instance of the standard MonacoEditor with a CodeEditorWidget as its Monaco delegeate.
405+ * In addition to the service customizability of the StandaloneCodeEditor,This editor allows greater customization the editor contributions active in the widget.
406+ * See {@link ICodeEditorWidgetOptions.contributions}.
407+ * @deprecated Most use cases for inline editors should be served by `createSimpleInline` instead.
408+ */
409+ async createSimpleInline ( uri : URI , node : HTMLElement , options ?: MonacoEditor . IOptions , widgetOptions ?: ICodeEditorWidgetOptions ) : Promise < SimpleMonacoEditor > {
410+ return this . doCreateEditor ( uri , async ( override , toDispose ) => {
411+ const overrides = override ? Array . from ( override ) : [ ] ;
412+ overrides . push ( [ IContextMenuService , { showContextMenu : ( ) => { /** no op! */ } } ] ) ;
413+ const document = await this . getModel ( uri , toDispose ) ;
414+ document . suppressOpenEditorWhenDirty = true ;
415+ const model = ( await document . load ( ) ) . textEditorModel ;
416+ const baseOptions : Partial < MonacoEditor . IOptions > = {
417+ model,
418+ autoSizing : false ,
419+ minHeight : 1 ,
420+ maxHeight : 1
421+ } ;
422+ const editorOptions = {
423+ ...baseOptions ,
424+ ...MonacoEditorProvider . inlineOptions ,
425+ ...options
426+ } ;
427+ return new SimpleMonacoEditor (
428+ uri ,
429+ document ,
430+ node ,
431+ this . services ,
432+ editorOptions ,
433+ overrides ,
434+ { isSimpleWidget : true , ...widgetOptions }
435+ ) ;
436+ } ) ;
437+ }
438+
396439 static inlineOptions : monaco . editor . IEditorConstructionOptions = {
397440 wordWrap : 'on' ,
398441 overviewRulerLanes : 0 ,
@@ -451,7 +494,7 @@ export class MonacoEditorProvider {
451494 override ,
452495 parentEditor
453496 )
454- ) as MonacoDiffEditor ;
497+ ) ;
455498 }
456499
457500 protected insertFinalNewline ( editor : MonacoEditor ) : monaco . editor . IIdentifiedSingleEditOperation [ ] {
0 commit comments