@@ -10,26 +10,26 @@ import { Code } from '../../vscode/code';
1010const RENAME_BOX = '.monaco-editor .monaco-editor.rename-box' ;
1111const RENAME_INPUT = `${ RENAME_BOX } .rename-input` ;
1212const EDITOR = filename => `.monaco-editor[data-uri$="${ filename } "]` ;
13+ const VIEW_LINES = filename => `${ EDITOR ( filename ) } .view-lines` ;
14+ const LINE_NUMBERS = filename => `${ EDITOR ( filename ) } .margin .margin-view-overlays .line-numbers` ;
1315
1416export class Editor {
1517
16- private static readonly VIEW_LINES = '.monaco-editor .view-lines' ;
17- private static readonly LINE_NUMBERS = '.monaco-editor .margin .margin-view-overlays .line-numbers' ;
1818 private static readonly FOLDING_EXPANDED = '.monaco-editor .margin .margin-view-overlays>:nth-child(${INDEX}) .folding' ;
1919 private static readonly FOLDING_COLLAPSED = `${ Editor . FOLDING_EXPANDED } .collapsed` ;
2020
2121 constructor ( private code : Code , private commands : Commands ) { }
2222
23- async findReferences ( term : string , line : number ) : Promise < References > {
24- await this . clickOnTerm ( term , line ) ;
23+ async findReferences ( filename : string , term : string , line : number ) : Promise < References > {
24+ await this . clickOnTerm ( filename , term , line ) ;
2525 await this . commands . runCommand ( 'Find All References' ) ;
2626 const references = new References ( this . code ) ;
2727 await references . waitUntilOpen ( ) ;
2828 return references ;
2929 }
3030
3131 async rename ( filename : string , line : number , from : string , to : string ) : Promise < void > {
32- await this . clickOnTerm ( from , line ) ;
32+ await this . clickOnTerm ( filename , from , line ) ;
3333 await this . commands . runCommand ( 'Rename Symbol' ) ;
3434
3535 await this . code . waitForActiveElement ( RENAME_INPUT ) ;
@@ -38,53 +38,59 @@ export class Editor {
3838 await this . code . dispatchKeybinding ( 'enter' ) ;
3939 }
4040
41- async gotoDefinition ( term : string , line : number ) : Promise < void > {
42- await this . clickOnTerm ( term , line ) ;
41+ async gotoDefinition ( filename : string , term : string , line : number ) : Promise < void > {
42+ await this . clickOnTerm ( filename , term , line ) ;
4343 await this . commands . runCommand ( 'Go to Definition' ) ;
4444 }
4545
46- async peekDefinition ( term : string , line : number ) : Promise < References > {
47- await this . clickOnTerm ( term , line ) ;
46+ async peekDefinition ( filename : string , term : string , line : number ) : Promise < References > {
47+ await this . clickOnTerm ( filename , term , line ) ;
4848 await this . commands . runCommand ( 'Peek Definition' ) ;
4949 const peek = new References ( this . code ) ;
5050 await peek . waitUntilOpen ( ) ;
5151 return peek ;
5252 }
5353
54- async waitForHighlightingLine ( line : number ) : Promise < void > {
55- const currentLineIndex = await this . getViewLineIndex ( line ) ;
54+ async waitForHighlightingLine ( filename : string , line : number ) : Promise < void > {
55+ const currentLineIndex = await this . getViewLineIndex ( filename , line ) ;
5656 if ( currentLineIndex ) {
5757 await this . code . waitForElement ( `.monaco-editor .view-overlays>:nth-child(${ currentLineIndex } ) .current-line` ) ;
5858 return ;
5959 }
6060 throw new Error ( 'Cannot find line ' + line ) ;
6161 }
6262
63- async getSelector ( term : string , line : number ) : Promise < string > {
64- const lineIndex = await this . getViewLineIndex ( line ) ;
65- const classNames = await this . getClassSelectors ( term , lineIndex ) ;
66- return `${ Editor . VIEW_LINES } >:nth-child(${ lineIndex } ) span span.${ classNames [ 0 ] } ` ;
63+ private async getSelector ( filename : string , term : string , line : number ) : Promise < string > {
64+ const lineIndex = await this . getViewLineIndex ( filename , line ) ;
65+ const classNames = await this . getClassSelectors ( filename , term , lineIndex ) ;
66+
67+ return `${ VIEW_LINES ( filename ) } >:nth-child(${ lineIndex } ) span span.${ classNames [ 0 ] } ` ;
6768 }
6869
69- async foldAtLine ( line : number ) : Promise < any > {
70- const lineIndex = await this . getViewLineIndex ( line ) ;
70+ async foldAtLine ( filename : string , line : number ) : Promise < any > {
71+ const lineIndex = await this . getViewLineIndex ( filename , line ) ;
7172 await this . code . waitAndClick ( Editor . FOLDING_EXPANDED . replace ( '${INDEX}' , '' + lineIndex ) ) ;
7273 await this . code . waitForElement ( Editor . FOLDING_COLLAPSED . replace ( '${INDEX}' , '' + lineIndex ) ) ;
7374 }
7475
75- async unfoldAtLine ( line : number ) : Promise < any > {
76- const lineIndex = await this . getViewLineIndex ( line ) ;
76+ async unfoldAtLine ( filename : string , line : number ) : Promise < any > {
77+ const lineIndex = await this . getViewLineIndex ( filename , line ) ;
7778 await this . code . waitAndClick ( Editor . FOLDING_COLLAPSED . replace ( '${INDEX}' , '' + lineIndex ) ) ;
7879 await this . code . waitForElement ( Editor . FOLDING_EXPANDED . replace ( '${INDEX}' , '' + lineIndex ) ) ;
7980 }
8081
81- async waitUntilShown ( line : number ) : Promise < void > {
82- await this . getViewLineIndex ( line ) ;
82+ private async clickOnTerm ( filename : string , term : string , line : number ) : Promise < void > {
83+ const selector = await this . getSelector ( filename , term , line ) ;
84+ await this . code . waitAndClick ( selector ) ;
8385 }
8486
85- async clickOnTerm ( term : string , line : number ) : Promise < void > {
86- const selector = await this . getSelector ( term , line ) ;
87- await this . code . waitAndClick ( selector ) ;
87+ async waitForEditorFocus ( filename : string , lineNumber : number , selectorPrefix = '' ) : Promise < void > {
88+ const editor = [ selectorPrefix || '' , EDITOR ( filename ) ] . join ( ' ' ) ;
89+ const line = `${ editor } .view-lines > .view-line:nth-child(${ lineNumber } )` ;
90+ const textarea = `${ editor } textarea` ;
91+
92+ await this . code . waitAndClick ( line ) ;
93+ await this . code . waitForActiveElement ( textarea ) ;
8894 }
8995
9096 async waitForTypeInEditor ( filename : string , text : string , selectorPrefix = '' ) : Promise < any > {
@@ -105,14 +111,14 @@ export class Editor {
105111 return this . code . waitForTextContent ( selector , undefined , c => accept ( c . replace ( / \u00a0 / g, ' ' ) ) ) ;
106112 }
107113
108- private async getClassSelectors ( term : string , viewline : number ) : Promise < string [ ] > {
109- const elements = await this . code . waitForElements ( `${ Editor . VIEW_LINES } >:nth-child(${ viewline } ) span span` , false , els => els . some ( el => el . textContent === term ) ) ;
114+ private async getClassSelectors ( filename : string , term : string , viewline : number ) : Promise < string [ ] > {
115+ const elements = await this . code . waitForElements ( `${ VIEW_LINES ( filename ) } >:nth-child(${ viewline } ) span span` , false , els => els . some ( el => el . textContent === term ) ) ;
110116 const { className } = elements . filter ( r => r . textContent === term ) [ 0 ] ;
111117 return className . split ( / \s / g) ;
112118 }
113119
114- private async getViewLineIndex ( line : number ) : Promise < number > {
115- const elements = await this . code . waitForElements ( Editor . LINE_NUMBERS , false , els => {
120+ private async getViewLineIndex ( filename : string , line : number ) : Promise < number > {
121+ const elements = await this . code . waitForElements ( LINE_NUMBERS ( filename ) , false , els => {
116122 return els . some ( el => el . textContent === `${ line } ` ) ;
117123 } ) ;
118124
0 commit comments