@@ -45,7 +45,9 @@ interface Signature {
45
45
saveSourceOnClose: (url : URL , content : string ) => void ;
46
46
selectDeclaration: (declaration : ModuleDeclaration ) => void ;
47
47
onFileSave: (status : ' started' | ' finished' ) => void ;
48
- onSetup: (updateCursorByName : (name : string ) => void ) => void ;
48
+ onSetup: (
49
+ updateCursorByName : (name : string , fieldName ? : string ) => void ,
50
+ ) => void ;
49
51
};
50
52
}
51
53
@@ -137,12 +139,36 @@ export default class CodeEditor extends Component<Signature> {
137
139
}
138
140
}
139
141
142
+ let selectedFieldName = this .operatorModeStateService .state .fieldSelection ;
143
+ let { selectedDeclaration } = this .args ;
144
+ if (
145
+ selectedFieldName &&
146
+ selectedDeclaration &&
147
+ ' possibleFields' in selectedDeclaration &&
148
+ selectedDeclaration .possibleFields
149
+ ) {
150
+ let possibleFields = selectedDeclaration .possibleFields ;
151
+ let field = possibleFields .get (selectedFieldName );
152
+ let loc =
153
+ field ?.path ?.node && ' loc' in field .path .node && field .path .node .loc
154
+ ? field .path .node .loc
155
+ : undefined ;
156
+ if (loc ) {
157
+ let { start } = loc ;
158
+ let { line, column } = start ;
159
+ // Adjusts column to make cursor position right after the field name
160
+ let fieldDecoratorTextLength = 8 ;
161
+ column = column + fieldDecoratorTextLength + selectedFieldName .length ;
162
+ return new Position (line , column );
163
+ }
164
+ }
165
+
140
166
let loc =
141
- this . args . selectedDeclaration ?.path ?.node &&
142
- ' body' in this . args . selectedDeclaration .path .node &&
143
- ' loc' in this . args . selectedDeclaration .path .node .body &&
144
- this . args . selectedDeclaration .path .node .body .loc
145
- ? this . args . selectedDeclaration ?.path ?.node .body .loc
167
+ selectedDeclaration ?.path ?.node &&
168
+ ' body' in selectedDeclaration .path .node &&
169
+ ' loc' in selectedDeclaration .path .node .body &&
170
+ selectedDeclaration .path .node .body .loc
171
+ ? selectedDeclaration ?.path ?.node .body .loc
146
172
: undefined ;
147
173
if (loc ) {
148
174
let { start } = loc ;
@@ -152,17 +178,37 @@ export default class CodeEditor extends Component<Signature> {
152
178
}
153
179
154
180
@action
155
- private updateMonacoCursorPositionByName(name : string ) {
181
+ private updateMonacoCursorPositionByName(name : string , fieldName ? : string ) {
156
182
let declaration = findDeclarationByName (name , this .declarations );
157
183
if (declaration === undefined ) return ;
158
- return this .updateMonacoCursorPositionByDeclaration (declaration );
184
+ return this .updateMonacoCursorPositionByDeclaration (declaration , fieldName );
159
185
}
160
186
161
187
@action
162
188
private updateMonacoCursorPositionByDeclaration(
163
189
declaration : ModuleDeclaration ,
190
+ fieldName ? : string ,
164
191
) {
165
192
if (
193
+ fieldName &&
194
+ ' possibleFields' in declaration &&
195
+ declaration .possibleFields
196
+ ) {
197
+ let possibleFields = declaration .possibleFields ;
198
+ let field = possibleFields .get (fieldName );
199
+ let loc =
200
+ field ?.path ?.node && ' loc' in field .path .node && field .path .node .loc
201
+ ? field .path .node .loc
202
+ : undefined ;
203
+ if (loc ) {
204
+ // Adjusts column to make cursor position right after the field name
205
+ let fieldDecoratorTextLength = 8 ;
206
+ let columnAdjustment = fieldDecoratorTextLength + fieldName .length ;
207
+ this .monacoService .updateCursorPosition (
208
+ new Position (loc .start .line , loc .start .column + columnAdjustment ),
209
+ );
210
+ }
211
+ } else if (
166
212
declaration .path ?.node &&
167
213
' body' in declaration .path .node &&
168
214
' loc' in declaration .path .node .body &&
0 commit comments