@@ -246,6 +246,7 @@ define(function (require, exports, module) {
246
246
}
247
247
248
248
var token = TokenUtils . getTokenAt ( current . cm , current . cm . posFromIndex ( endIndex ) ) ,
249
+ commaString = "," ,
249
250
isLastNode ,
250
251
templateParams ,
251
252
parentNode ,
@@ -267,16 +268,38 @@ define(function (require, exports, module) {
267
268
268
269
var propertyNodeArray = parentNode . properties ;
269
270
// Find the last Propery Node before endIndex
270
- var properyEndNode = propertyNodeArray . find ( function ( element ) {
271
+ var properyNodeIndex = propertyNodeArray . findIndex ( function ( element ) {
271
272
return ( endIndex >= element . start && endIndex < element . end ) ;
272
273
} ) ;
273
274
275
+ var propertyNode = propertyNodeArray [ properyNodeIndex ] ;
276
+
274
277
//Get Current Selected Property End Index;
275
- propertyEndPos = editor . posFromIndex ( properyEndNode . end ) ;
278
+ propertyEndPos = editor . posFromIndex ( propertyNode . end ) ;
276
279
277
280
278
281
//We have to add ',' so we need to find position of current property selected
279
282
isLastNode = current . isLastNodeInScope ( current . ast , endIndex ) ;
283
+ var nextPropertNode , nextPropertyStartPos ;
284
+ if ( ! isLastNode && properyNodeIndex + 1 <= propertyNodeArray . length - 1 ) {
285
+ nextPropertNode = propertyNodeArray [ properyNodeIndex + 1 ] ;
286
+ nextPropertyStartPos = editor . posFromIndex ( nextPropertNode . start ) ;
287
+
288
+ if ( propertyEndPos . line !== nextPropertyStartPos . line ) {
289
+ propertyEndPos = current . lineEndPosition ( current . startPos . line ) ;
290
+ } else {
291
+ propertyEndPos = nextPropertyStartPos ;
292
+ commaString = ", " ;
293
+ }
294
+ }
295
+
296
+ var getSetPos ;
297
+ if ( isLastNode ) {
298
+ getSetPos = current . document . adjustPosForChange ( propertyEndPos , commaString . split ( "\n" ) ,
299
+ propertyEndPos , propertyEndPos ) ;
300
+ } else {
301
+ getSetPos = propertyEndPos ;
302
+ }
280
303
templateParams = {
281
304
"getName" : token . string ,
282
305
"setName" : token . string ,
@@ -288,18 +311,17 @@ define(function (require, exports, module) {
288
311
current . document . batchOperation ( function ( ) {
289
312
if ( isLastNode ) {
290
313
//Add ',' in the end of current line
291
- current . document . replaceRange ( "," , propertyEndPos , propertyEndPos ) ;
314
+ current . document . replaceRange ( commaString , propertyEndPos , propertyEndPos ) ;
292
315
}
293
- propertyEndPos . ch ++ ;
294
316
295
- current . editor . setSelection ( propertyEndPos ) ; //Selection on line end
317
+ current . editor . setSelection ( getSetPos ) ; //Selection on line end
296
318
297
319
// Add getters and setters for given token using template at current cursor position
298
320
current . replaceTextFromTemplate ( GETTERS_SETTERS , templateParams ) ;
299
321
300
322
if ( ! isLastNode ) {
301
323
// Add ',' at the end setter
302
- current . document . replaceRange ( "," , current . editor . getSelection ( ) . start , current . editor . getSelection ( ) . start ) ;
324
+ current . document . replaceRange ( commaString , current . editor . getSelection ( ) . start , current . editor . getSelection ( ) . start ) ;
303
325
}
304
326
} ) ;
305
327
}
0 commit comments