import { Code } from './code' ; export class Editors { constructor ( private code ) { } async saveOpenedFile ( ) { if ( process . platform === 'darwin' ) { await this . code . dispatchKeybinding ( 'cmd+s' ) ; } else { await this . code . dispatchKeybinding ( 'ctrl+s' ) ; } } async selectTab ( fileName ) { let error = undefined ; let retries = 0 ; while ( retries < 10 ) { await this . code . waitAndClick ( `.tabs-container div.tab[data-resource-name$="${ fileName }"]` ) ; await this . code . dispatchKeybinding ( process . platform === 'darwin' ? 'cmd+1' : 'ctrl+1' ) ; try { await this . waitForEditorFocus ( fileName , 50 ) ; return ; } catch ( e ) { error = e ; retries ++ ; } } throw error ; } async waitForEditorFocus ( fileName , retryCount ? ) { await this . waitForActiveTab ( fileName , undefined , retryCount ) ; await this . waitForActiveEditor ( fileName , retryCount ) ; } async waitForActiveTab ( fileName , isDirty = false , retryCount ? ) { await this . code . waitForElement ( `.tabs-container div.tab.active${ isDirty ? '.dirty' : '' }[aria-selected="true"][data-resource-name$="${ fileName }"]` , undefined , retryCount ) ; } async waitForActiveEditor ( fileName , retryCount ? ) { const selector = `.editor-instance .monaco-editor[data-uri$="${ fileName }"] textarea` ; return this . code . waitForActiveElement ( selector , retryCount ) ; } async waitForTab ( fileName , isDirty = false ) { await this . code . waitForElement ( `.tabs-container div.tab${ isDirty ? '.dirty' : '' }[data-resource-name$="${ fileName }"]` ) ; } async newUntitledFile ( ) { if ( process . platform === 'darwin' ) { await this . code . dispatchKeybinding ( 'cmd+n' ) ; } else { await this . code . dispatchKeybinding ( 'ctrl+n' ) ; } await this . waitForEditorFocus ( 'Untitled-1' ) ; } }