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EAAE,oCAAoC;KACrF;IAED,SAAgB,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,YAAY,EAAE,CAE7D;IAED,SAAgB,UAAU,CAAC,OAAO,EAAE,aAAa,GAAG,YAAY,GAAG,SAAS,CAE3E;IAED,SAAgB,SAAS,CAAC,OAAO,EAAE,aAAa,GAAG,YAAY,GAAG,SAAS,CAE1E;IAED,SAAgB,GAAG,CAAC,YAAY,EAAE,YAAY,GAAG,SAAS,GAAG,YAAY,GAAG,SAAS,CAKpF;IAED,SAAgB,cAAc,CAAC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,iBAAiB,GAAG,YAAY,EAAE,CAElG;IAED,SAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,WAAW,GAAG,SAAS,GAAG,YAAY,GAAG,SAAS,CAQ7H;CACF","file":"../../src/browser/monaco-editor.d.ts","sourcesContent":["import {inject, injectable, unmanaged} from 'inversify';\r\nimport {\r\n  DeltaDecorationParams,\r\n  Dimension,\r\n  EditorMouseEvent,\r\n  EncodingMode,\r\n  Position,\r\n  Range,\r\n  ReplaceTextParams,\r\n  RevealPositionOptions,\r\n  RevealRangeOptions,\r\n  TextDocumentChangeEvent,\r\n  TextEditor\r\n} from '@tartjs/editor/lib/browser/editor';\r\nimport {ElementExt} from '@lumino/domutils'\r\nimport {Disposable, DisposableCollection, Emitter, Event, TextDocumentContentChangeDelta,} from '@tartjs/core/lib/common';\r\n\r\nimport URI from '@tartjs/core/lib/common/uri';\r\nimport {MonacoEditorModel} from './monaco-editor-model';\r\nimport {MonacoToProtocolConverter} from './monaco-to-protocol-converter';\r\nimport {ProtocolToMonacoConverter} from './protocol-to-monaco-converter';\r\nimport {ContextKeyService} from '@tartjs/core/lib/browser/context-key-service';\r\nimport {UTF8} from '@tartjs/core/lib/common/encodings';\r\nimport {TextEdit} from 'vscode-languageserver-types';\r\nimport IStandaloneEditorConstructionOptions = monaco.editor.IStandaloneEditorConstructionOptions;\r\nimport IModelDeltaDecoration = monaco.editor.IModelDeltaDecoration;\r\nimport IEditorOverrideServices = monaco.editor.IEditorOverrideServices;\r\nimport IStandaloneCodeEditor = monaco.editor.IStandaloneCodeEditor;\r\nimport IIdentifiedSingleEditOperation = monaco.editor.IIdentifiedSingleEditOperation;\r\nimport IBoxSizing = ElementExt.IBoxSizing;\r\nimport {EditorDecoration} from '@tartjs/editor/lib/browser/decorations/editor-decoration';\r\nimport {EditorManager} from '@tartjs/editor/lib/browser/editor-manager';\r\nimport {EditorWidget} from '@tartjs/editor/lib/browser/editor-widget';\r\n\r\n\r\n@injectable()\r\nexport class MonacoEditorServices {\r\n\r\n  @inject(MonacoToProtocolConverter)\r\n  protected readonly m2p: MonacoToProtocolConverter;\r\n\r\n  @inject(ProtocolToMonacoConverter)\r\n  protected readonly p2m: ProtocolToMonacoConverter;\r\n\r\n  @inject(ContextKeyService)\r\n  protected readonly contextKeyService: ContextKeyService;\r\n\r\n  constructor(@unmanaged() services: MonacoEditorServices) {\r\n    Object.assign(this, services);\r\n  }\r\n}\r\n\r\nexport class MonacoEditor extends MonacoEditorServices implements TextEditor {\r\n\r\n  onEncodingChanged: Event<string>;\r\n  readonly documents = new Set<MonacoEditorModel>();\r\n  protected readonly toDispose = new DisposableCollection();\r\n  protected readonly autoSizing: boolean;\r\n  protected readonly minHeight: number;\r\n  protected readonly maxHeight: number;\r\n  protected editor: IStandaloneCodeEditor;\r\n  protected readonly onCursorPositionChangedEmitter = new Emitter<Position>();\r\n  protected readonly onSelectionChangedEmitter = new Emitter<Range>();\r\n  protected readonly onFocusChangedEmitter = new Emitter<boolean>();\r\n  protected readonly onDocumentContentChangedEmitter = new Emitter<TextDocumentChangeEvent>();\r\n  protected readonly onMouseDownEmitter = new Emitter<EditorMouseEvent>();\r\n  protected readonly onLanguageChangedEmitter = new Emitter<string>();\r\n  readonly onLanguageChanged = this.onLanguageChangedEmitter.event;\r\n  protected readonly onScrollChangedEmitter = new Emitter<void>();\r\n  // eslint-disable-next-line no-null/no-null\r\n  protected readonly onResizeEmitter = new Emitter<Dimension | null>();\r\n  readonly onDidResize = this.onResizeEmitter.event;\r\n\r\n  constructor(\r\n      readonly uri: URI,\r\n      readonly document: MonacoEditorModel,\r\n      readonly node: HTMLElement,\r\n      services: MonacoEditorServices,\r\n      options?: MonacoEditor.IOptions,\r\n      override?: IEditorOverrideServices\r\n  ) {\r\n    super(services);\r\n    this.toDispose.pushAll([\r\n      this.onCursorPositionChangedEmitter,\r\n      this.onSelectionChangedEmitter,\r\n      this.onFocusChangedEmitter,\r\n      this.onDocumentContentChangedEmitter,\r\n      this.onMouseDownEmitter,\r\n      this.onLanguageChangedEmitter,\r\n      this.onScrollChangedEmitter\r\n    ]);\r\n    this.document = document;\r\n    this.onEncodingChanged = this.document.onDidChangeEncoding;\r\n    this.documents.add(document);\r\n\r\n    this.autoSizing = options && options.autoSizing !== undefined ? options.autoSizing : false;\r\n    this.minHeight = options && options.minHeight !== undefined ? options.minHeight : -1;\r\n    this.maxHeight = options && options.maxHeight !== undefined ? options.maxHeight : -1;\r\n    this.toDispose.push(this.create(options, override));\r\n    this.addHandlers(this.editor);\r\n  }\r\n\r\n  get onDispose(): Event<void> {\r\n    return this.toDispose.onDispose;\r\n  }\r\n\r\n  get onDocumentContentChanged(): Event<TextDocumentChangeEvent> {\r\n    return this.onDocumentContentChangedEmitter.event;\r\n  }\r\n\r\n  get cursor(): Position {\r\n    const {lineNumber, column} = this.editor.getPosition()!;\r\n    return this.m2p.asPosition(lineNumber, column);\r\n  }\r\n\r\n  set cursor(cursor: Position) {\r\n    const position = this.p2m.asPosition(cursor);\r\n    this.editor.setPosition(position);\r\n  }\r\n\r\n  get onCursorPositionChanged(): Event<Position> {\r\n    return this.onCursorPositionChangedEmitter.event;\r\n  }\r\n\r\n  get selection(): Range {\r\n    return this.m2p.asRange(this.editor.getSelection()!);\r\n  }\r\n\r\n  set selection(selection: Range) {\r\n    const range = this.p2m.asRange(selection);\r\n    this.editor.setSelection(range);\r\n  }\r\n\r\n  get onSelectionChanged(): Event<Range> {\r\n    return this.onSelectionChangedEmitter.event;\r\n  }\r\n\r\n  get onScrollChanged(): Event<void> {\r\n    return this.onScrollChangedEmitter.event;\r\n  }\r\n\r\n  get onFocusChanged(): Event<boolean> {\r\n    return this.onFocusChangedEmitter.event;\r\n  }\r\n\r\n  get onMouseDown(): Event<EditorMouseEvent> {\r\n    return this.onMouseDownEmitter.event;\r\n  }\r\n\r\n  get commandService(): monaco.commands.ICommandService {\r\n    return this.editor._commandService;\r\n  }\r\n\r\n  get instantiationService(): monaco.instantiation.IInstantiationService {\r\n    return this.editor._instantiationService;\r\n  }\r\n\r\n  /* `true` because it is derived from an URI during the instantiation */\r\n  protected _languageAutoDetected = true;\r\n\r\n  get languageAutoDetected(): boolean {\r\n    return this._languageAutoDetected;\r\n  }\r\n\r\n  getEncoding(): string {\r\n    return this.document.getEncoding() || UTF8;\r\n  }\r\n\r\n  setEncoding(encoding: string, mode: EncodingMode): Promise<void> {\r\n    return this.document.setEncoding(encoding, mode);\r\n  }\r\n\r\n  getVisibleRanges(): Range[] {\r\n    return this.editor.getVisibleRanges().map(range => this.m2p.asRange(range));\r\n  }\r\n\r\n  revealPosition(raw: Position, options: RevealPositionOptions = {vertical: 'center'}): void {\r\n    const position = this.p2m.asPosition(raw);\r\n    switch (options.vertical) {\r\n      case 'auto':\r\n        this.editor.revealPosition(position);\r\n        break;\r\n      case 'center':\r\n        this.editor.revealPositionInCenter(position);\r\n        break;\r\n      case 'centerIfOutsideViewport':\r\n        this.editor.revealPositionInCenterIfOutsideViewport(position);\r\n        break;\r\n    }\r\n  }\r\n\r\n  revealRange(raw: Range, options: RevealRangeOptions = {at: 'center'}): void {\r\n    const range = this.p2m.asRange(raw);\r\n    switch (options.at) {\r\n      case 'top':\r\n        this.editor.revealRangeAtTop(range!);\r\n        break;\r\n      case 'center':\r\n        this.editor.revealRangeInCenter(range!);\r\n        break;\r\n      case 'centerIfOutsideViewport':\r\n        this.editor.revealRangeInCenterIfOutsideViewport(range!);\r\n        break;\r\n      case 'auto':\r\n        this.editor.revealRange(range!);\r\n        break;\r\n    }\r\n  }\r\n\r\n  focus(): void {\r\n    /**\r\n     * `this.editor.focus` forcefully changes the focus editor state,\r\n     * regardless whether the textarea actually received the focus.\r\n     * It could lead to issues like https://github.com/eclipse-wm/wm/issues/7902\r\n     * Instead we focus the underlying textarea.\r\n     */\r\n    const node = this.editor.getDomNode();\r\n    if (node) {\r\n      const textarea = node.querySelector('textarea') as HTMLElement;\r\n      textarea.focus();\r\n    }\r\n  }\r\n\r\n  blur(): void {\r\n    const node = this.editor.getDomNode();\r\n    if (node) {\r\n      const textarea = node.querySelector('textarea') as HTMLElement;\r\n      textarea.blur();\r\n    }\r\n  }\r\n\r\n  isFocused({strict}: { strict: boolean } = {strict: false}): boolean {\r\n    if (!this.editor.hasTextFocus()) {\r\n      return false;\r\n    }\r\n    if (strict) {\r\n      return !this.isSuggestWidgetVisible() && !this.isFindWidgetVisible() && !this.isRenameInputVisible();\r\n    }\r\n    return true;\r\n  }\r\n\r\n  /**\r\n   * `true` if the suggest widget is visible in the editor. Otherwise, `false`.\r\n   */\r\n  isSuggestWidgetVisible(): boolean {\r\n    return this.contextKeyService.match('suggestWidgetVisible', this.editor.getDomNode() || this.node);\r\n  }\r\n\r\n  /**\r\n   * `true` if the find (and replace) widget is visible in the editor. Otherwise, `false`.\r\n   */\r\n  isFindWidgetVisible(): boolean {\r\n    return this.contextKeyService.match('findWidgetVisible', this.editor.getDomNode() || this.node);\r\n  }\r\n\r\n  /**\r\n   * `true` if the name rename refactoring input HTML element is visible. Otherwise, `false`.\r\n   */\r\n  isRenameInputVisible(): boolean {\r\n    return this.contextKeyService.match('renameInputVisible', this.editor.getDomNode() || this.node);\r\n  }\r\n\r\n  dispose(): void {\r\n    this.toDispose.dispose();\r\n  }\r\n\r\n  // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n  trigger(source: string, handlerId: string, payload: any): void {\r\n    this.editor.trigger(source, handlerId, payload);\r\n  }\r\n\r\n  getControl(): IStandaloneCodeEditor {\r\n    return this.editor;\r\n  }\r\n\r\n  refresh(): void {\r\n    this.autoresize();\r\n  }\r\n\r\n  resizeToFit(): void {\r\n    this.autoresize();\r\n    // eslint-disable-next-line no-null/no-null\r\n    this.onResizeEmitter.fire(null);\r\n  }\r\n\r\n  setSize(dimension: Dimension): void {\r\n    this.resize(dimension);\r\n    this.onResizeEmitter.fire(dimension);\r\n  }\r\n\r\n  isActionSupported(id: string): boolean {\r\n    const action = this.editor.getAction(id);\r\n    return !!action && action.isSupported();\r\n  }\r\n\r\n  async runAction(id: string): Promise<void> {\r\n    const action = this.editor.getAction(id);\r\n    if (action && action.isSupported()) {\r\n      await action.run();\r\n    }\r\n  }\r\n\r\n  deltaDecorations(params: DeltaDecorationParams): string[] {\r\n    const oldDecorations = params.oldDecorations;\r\n    const newDecorations = this.toDeltaDecorations(params);\r\n    return this.editor.deltaDecorations(oldDecorations, newDecorations);\r\n  }\r\n\r\n  getLinesDecorations(startLineNumber: number, endLineNumber: number): (EditorDecoration & Readonly<{ id: string }>)[] {\r\n    const toPosition = (line: number): monaco.Position => this.p2m.asPosition({line, character: 0});\r\n    const start = toPosition(startLineNumber).lineNumber;\r\n    const end = toPosition(endLineNumber).lineNumber;\r\n    return this.editor\r\n        .getModel()!\r\n        .getLinesDecorations(start, end)\r\n        .map(this.toEditorDecoration.bind(this));\r\n  }\r\n\r\n  getVisibleColumn(position: Position): number {\r\n    return this.editor.getVisibleColumnFromPosition(this.p2m.asPosition(position));\r\n  }\r\n\r\n  async replaceText(params: ReplaceTextParams): Promise<boolean> {\r\n    const edits: IIdentifiedSingleEditOperation[] = params.replaceOperations.map(param => {\r\n      const range = monaco.Range.fromPositions(this.p2m.asPosition(param.range.start), this.p2m.asPosition(param.range.end));\r\n      return {\r\n        forceMoveMarkers: true,\r\n        identifier: {\r\n          major: range.startLineNumber,\r\n          minor: range.startColumn\r\n        },\r\n        range,\r\n        text: param.text\r\n      };\r\n    });\r\n    return this.editor.executeEdits(params.source, edits);\r\n  }\r\n\r\n  executeEdits(edits: TextEdit[]): boolean {\r\n    return this.editor.executeEdits('MonacoEditor', this.p2m.asTextEdits(edits) as IIdentifiedSingleEditOperation[]);\r\n  }\r\n\r\n  storeViewState(): object {\r\n    return this.editor.saveViewState()!;\r\n  }\r\n\r\n  restoreViewState(state: monaco.editor.ICodeEditorViewState): void {\r\n    this.editor.restoreViewState(state);\r\n  }\r\n\r\n  async detectLanguage(): Promise<void> {\r\n    const modeService = monaco.services.StaticServices.modeService.get();\r\n    const firstLine = this.document.textEditorModel.getLineContent(1);\r\n    const model = this.getControl().getModel();\r\n    const language = modeService.createByFilepathOrFirstLine(model && model.uri, firstLine);\r\n    this.setLanguage(language.languageIdentifier.language);\r\n    this._languageAutoDetected = true;\r\n  }\r\n\r\n  setLanguage(languageId: string): void {\r\n    for (const document of this.documents) {\r\n      monaco.editor.setModelLanguage(document.textEditorModel, languageId);\r\n    }\r\n  }\r\n\r\n  getResourceUri(): URI {\r\n    return this.uri;\r\n  }\r\n\r\n  createMoveToUri(resourceUri: URI): URI {\r\n    return this.uri.withPath(resourceUri.path);\r\n  }\r\n\r\n  protected create(options?: IStandaloneEditorConstructionOptions, override?: monaco.editor.IEditorOverrideServices): Disposable {\r\n    return this.editor = monaco.editor.create(this.node, {\r\n      ...options,\r\n      lightbulb: {enabled: true},\r\n      fixedOverflowWidgets: true,\r\n      scrollbar: {\r\n        useShadows: false,\r\n        verticalHasArrows: false,\r\n        horizontalHasArrows: false,\r\n        verticalScrollbarSize: 10,\r\n        horizontalScrollbarSize: 10\r\n      }\r\n    }, override);\r\n  }\r\n\r\n  protected addHandlers(codeEditor: IStandaloneCodeEditor): void {\r\n    this.toDispose.push(codeEditor.onDidChangeModelLanguage(e =>\r\n        this.fireLanguageChanged(e.newLanguage)\r\n    ));\r\n    this.toDispose.push(codeEditor.onDidChangeConfiguration(() => this.refresh()));\r\n    this.toDispose.push(codeEditor.onDidChangeModel(() => this.refresh()));\r\n    this.toDispose.push(codeEditor.onDidChangeModelContent(e => {\r\n      this.refresh();\r\n      this.onDocumentContentChangedEmitter.fire({\r\n        document: this.document,\r\n        contentChanges: e.changes.map(this.mapModelContentChange.bind(this))\r\n      });\r\n    }));\r\n    this.toDispose.push(codeEditor.onDidChangeCursorPosition(() =>\r\n        this.onCursorPositionChangedEmitter.fire(this.cursor)\r\n    ));\r\n    this.toDispose.push(codeEditor.onDidChangeCursorSelection(() =>\r\n        this.onSelectionChangedEmitter.fire(this.selection)\r\n    ));\r\n    this.toDispose.push(codeEditor.onDidFocusEditorText(() =>\r\n        this.onFocusChangedEmitter.fire(this.isFocused())\r\n    ));\r\n    this.toDispose.push(codeEditor.onDidBlurEditorText(() =>\r\n        this.onFocusChangedEmitter.fire(this.isFocused())\r\n    ));\r\n    this.toDispose.push(codeEditor.onMouseDown(e => {\r\n      const {element, position, range} = e.target;\r\n      this.onMouseDownEmitter.fire({\r\n        target: {\r\n          ...e.target,\r\n          element: element || undefined,\r\n          mouseColumn: this.m2p.asPosition(undefined, e.target.mouseColumn).character,\r\n          range: range && this.m2p.asRange(range) || undefined,\r\n          position: position && this.m2p.asPosition(position.lineNumber, position.column) || undefined\r\n        },\r\n        event: e.event.browserEvent\r\n      });\r\n    }));\r\n    this.toDispose.push(codeEditor.onDidScrollChange(e => {\r\n      this.onScrollChangedEmitter.fire(undefined);\r\n    }));\r\n  }\r\n\r\n  protected mapModelContentChange(change: monaco.editor.IModelContentChange): TextDocumentContentChangeDelta {\r\n    return {\r\n      range: this.m2p.asRange(change.range),\r\n      rangeLength: change.rangeLength,\r\n      text: change.text\r\n    };\r\n  }\r\n\r\n  protected autoresize(): void {\r\n    if (this.autoSizing) {\r\n      // eslint-disable-next-line no-null/no-null\r\n      this.resize(null);\r\n    }\r\n  }\r\n\r\n  protected resize(dimension: Dimension | null): void {\r\n    if (this.node) {\r\n      const layoutSize = this.computeLayoutSize(this.node, dimension);\r\n      this.editor.layout(layoutSize);\r\n    }\r\n  }\r\n\r\n  protected computeLayoutSize(hostNode: HTMLElement, dimension: monaco.editor.IDimension | null): monaco.editor.IDimension {\r\n    if (dimension && dimension.width >= 0 && dimension.height >= 0) {\r\n      return dimension;\r\n    }\r\n    const boxSizing = ElementExt.boxSizing(hostNode);\r\n\r\n    const width = (!dimension || dimension.width < 0) ?\r\n        this.getWidth(hostNode, boxSizing) :\r\n        dimension.width;\r\n\r\n    const height = (!dimension || dimension.height < 0) ?\r\n        this.getHeight(hostNode, boxSizing) :\r\n        dimension.height;\r\n\r\n    return {width, height};\r\n  }\r\n\r\n  protected getWidth(hostNode: HTMLElement, boxSizing: IBoxSizing): number {\r\n    return hostNode.offsetWidth - boxSizing.horizontalSum;\r\n  }\r\n\r\n  protected getHeight(hostNode: HTMLElement, boxSizing: IBoxSizing): number {\r\n    if (!this.autoSizing) {\r\n      return hostNode.offsetHeight - boxSizing.verticalSum;\r\n    }\r\n\r\n    const lineHeight = this.editor.getOption(monaco.editor.EditorOption.lineHeight);\r\n    const lineCount = this.editor.getModel()!.getLineCount();\r\n    const contentHeight = lineHeight * lineCount;\r\n\r\n    const horizontalScrollbarHeight = this.editor.getLayoutInfo().horizontalScrollbarHeight;\r\n\r\n    const editorHeight = contentHeight + horizontalScrollbarHeight;\r\n    if (this.minHeight >= 0) {\r\n      const minHeight = lineHeight * this.minHeight + horizontalScrollbarHeight;\r\n      if (editorHeight < minHeight) {\r\n        return minHeight;\r\n      }\r\n    }\r\n    if (this.maxHeight >= 0) {\r\n      const maxHeight = lineHeight * this.maxHeight + horizontalScrollbarHeight;\r\n      return Math.min(maxHeight, editorHeight);\r\n    }\r\n    return editorHeight;\r\n  }\r\n\r\n  protected toDeltaDecorations(params: DeltaDecorationParams): IModelDeltaDecoration[] {\r\n    // @ts-ignore\r\n    return params.newDecorations.map(decoration => <IModelDeltaDecoration>{\r\n      ...decoration,\r\n      range: this.p2m.asRange(decoration.range),\r\n    });\r\n  }\r\n\r\n  protected toEditorDecoration(decoration: monaco.editor.IModelDecoration): EditorDecoration & Readonly<{ id: string }> {\r\n    const range = this.m2p.asRange(decoration.range);\r\n    const {id, options} = decoration;\r\n    // @ts-ignore\r\n    return {\r\n      options,\r\n      range,\r\n      id\r\n    } as EditorDecoration & Readonly<{ id: string }>;\r\n  }\r\n\r\n  protected fireLanguageChanged(languageId: string): void {\r\n    this._languageAutoDetected = false;\r\n    this.onLanguageChangedEmitter.fire(languageId);\r\n  }\r\n\r\n}\r\n\r\nexport namespace MonacoEditor {\r\n  export interface ICommonOptions {\r\n    /**\r\n     * Whether an editor should be auto resized on a content change.\r\n     *\r\n     * #### Fixme\r\n     * remove when https://github.com/Microsoft/monaco-editor/issues/103 is resolved\r\n     */\r\n    autoSizing?: boolean;\r\n    /**\r\n     * A minimal height of an editor in lines.\r\n     *\r\n     * #### Fixme\r\n     * remove when https://github.com/Microsoft/monaco-editor/issues/103 is resolved\r\n     */\r\n    minHeight?: number;\r\n    /**\r\n     * A maximal height of an editor in lines.\r\n     *\r\n     * #### Fixme\r\n     * remove when https://github.com/Microsoft/monaco-editor/issues/103 is resolved\r\n     */\r\n    maxHeight?: number;\r\n  }\r\n\r\n  export interface IOptions extends ICommonOptions, IStandaloneEditorConstructionOptions {\r\n  }\r\n\r\n  export function getAll(manager: EditorManager): MonacoEditor[] {\r\n    return manager.all.map(e => get(e)).filter(e => !!e) as MonacoEditor[];\r\n  }\r\n\r\n  export function getCurrent(manager: EditorManager): MonacoEditor | undefined {\r\n    return get(manager.currentEditor);\r\n  }\r\n\r\n  export function getActive(manager: EditorManager): MonacoEditor | undefined {\r\n    return get(manager.activeEditor);\r\n  }\r\n\r\n  export function get(editorWidget: EditorWidget | undefined): MonacoEditor | undefined {\r\n    if (editorWidget && editorWidget.editor instanceof MonacoEditor) {\r\n      return editorWidget.editor;\r\n    }\r\n    return undefined;\r\n  }\r\n\r\n  export function findByDocument(manager: EditorManager, document: MonacoEditorModel): MonacoEditor[] {\r\n    return getAll(manager).filter(editor => editor.documents.has(document));\r\n  }\r\n\r\n  export function getWidgetFor(manager: EditorManager, control: monaco.editor.ICodeEditor | undefined): EditorWidget | undefined {\r\n    if (!control) {\r\n      return undefined;\r\n    }\r\n    return manager.all.find(widget => {\r\n      const editor = get(widget);\r\n      return !!editor && editor.getControl() === control;\r\n    });\r\n  }\r\n}\r\n"]}