@@ -36,6 +36,7 @@ define([
36
36
originObj : '' ,
37
37
tempObj : '_vp' ,
38
38
returnObj : '_vp' ,
39
+ inplace : false ,
39
40
columnList : [ ] ,
40
41
indexList : [ ] ,
41
42
selected : [ ] ,
@@ -105,7 +106,13 @@ define([
105
106
// initialize state values
106
107
that . state . originObj = origin ;
107
108
that . state . tempObj = '_vp' ;
109
+ that . state . returnObj = that . state . tempObj ;
110
+ that . state . inplace = false ;
108
111
that . initState ( ) ;
112
+
113
+ // reset return obj
114
+ $ ( that . wrapSelector ( '#vp_feReturn' ) ) . val ( that . state . tempObj ) ;
115
+ $ ( that . wrapSelector ( '#inplace' ) ) . prop ( 'checked' , false ) ;
109
116
110
117
// reset table
111
118
$ ( that . wrapSelector ( '.' + VP_FE_TABLE ) ) . replaceWith ( function ( ) {
@@ -133,10 +140,33 @@ define([
133
140
if ( returnVariable == '' ) {
134
141
returnVariable = that . state . tempObj ;
135
142
}
143
+ // check if it's same with origin obj
144
+ if ( returnVariable === that . state . originObj ) {
145
+ $ ( that . wrapSelector ( '#inplace' ) ) . prop ( 'checked' , true ) ;
146
+ that . state . inplace = true ;
147
+ } else {
148
+ $ ( that . wrapSelector ( '#inplace' ) ) . prop ( 'checked' , false ) ;
149
+ that . state . inplace = false ;
150
+ }
151
+
152
+ // show preview with new return variable
153
+ that . state . returnObj = returnVariable ;
154
+ that . setPreview ( that . getCurrentCode ( ) ) ;
155
+ } ) ;
156
+
157
+ // check/uncheck inplace
158
+ $ ( this . wrapSelector ( '#inplace' ) ) . on ( 'change' , function ( ) {
159
+ let checked = $ ( this ) . prop ( 'checked' ) ;
160
+ let returnVariable = '_vp' ;
161
+ if ( checked === true ) {
162
+ returnVariable = that . state . originObj ;
163
+ }
164
+ $ ( that . wrapSelector ( '#vp_feReturn' ) ) . val ( returnVariable ) ;
165
+
136
166
// show preview with new return variable
137
- var newCode = that . state . steps [ that . state . steps . length - 1 ] ;
138
- that . setPreview ( newCode . replaceAll ( that . state . tempObj , returnVariable ) ) ;
167
+ that . state . inplace = checked ;
139
168
that . state . returnObj = returnVariable ;
169
+ that . setPreview ( that . getCurrentCode ( ) ) ;
140
170
} ) ;
141
171
142
172
// menu on column
@@ -483,22 +513,24 @@ define([
483
513
render ( ) {
484
514
super . render ( ) ;
485
515
486
- this . loadVariableList ( ) ;
487
-
488
516
var {
489
- originObj,
490
517
returnObj,
518
+ inplace,
491
519
steps
492
520
} = this . state ;
521
+
522
+ this . loadVariableList ( ) ;
493
523
494
- $ ( this . wrapSelector ( '#vp_feVariable' ) ) . val ( originObj ) ;
524
+ $ ( this . wrapSelector ( '#vp_feVariable' ) ) . val ( this . state . originObj ) ;
495
525
496
526
$ ( this . wrapSelector ( '#vp_feReturn' ) ) . val ( returnObj ) ;
527
+
528
+ $ ( this . wrapSelector ( '#inplace' ) ) . prop ( 'checked' , inplace ) ;
497
529
498
530
// execute all steps
499
531
if ( steps && steps . length > 0 ) {
500
532
var code = steps . join ( '\n' ) ;
501
- this . state . steps = [ ] ;
533
+ // this.state.steps = [];
502
534
this . loadCode ( code ) ;
503
535
}
504
536
}
@@ -537,13 +569,42 @@ define([
537
569
return tag . toString ( ) ;
538
570
}
539
571
572
+ /**
573
+ * Get last code to set preview
574
+ * @returns
575
+ */
576
+ getCurrentCode ( ) {
577
+ let { inplace, steps, tempObj, returnObj } = this . state ;
578
+ let codeList = steps ;
579
+ if ( inplace === true ) {
580
+ codeList = steps . slice ( 1 , steps . length ) ;
581
+ }
582
+
583
+ // get last code
584
+ let currentCode = codeList [ codeList . length - 1 ] ;
585
+ if ( currentCode && currentCode != '' ) {
586
+ currentCode = currentCode . replaceAll ( tempObj , returnObj ) ;
587
+ } else {
588
+ currentCode = '' ;
589
+ }
590
+ return currentCode ;
591
+ }
592
+
540
593
generateCode ( ) {
541
- var code = this . state . steps . join ( '\n' ) ;
594
+ var code = '' ;
595
+ // if inplace is true, join steps without .copy()
596
+ if ( this . state . inplace === true ) {
597
+ code = this . state . steps . slice ( 1 ) . join ( '\n' ) ;
598
+ } else {
599
+ code = this . state . steps . join ( '\n' ) ;
600
+ }
542
601
var returnVariable = $ ( this . wrapSelector ( '#vp_feReturn' ) ) . val ( ) ;
543
602
if ( returnVariable != '' ) {
544
603
code = code . replaceAll ( this . state . tempObj , returnVariable ) ;
545
604
546
- code += '\n' + returnVariable ;
605
+ if ( code != '' ) {
606
+ code += '\n' + returnVariable ;
607
+ }
547
608
} else {
548
609
code += '\n' + this . state . tempObj ;
549
610
}
@@ -570,8 +631,11 @@ define([
570
631
571
632
setPreview ( previewCodeStr ) {
572
633
// get only last line of code
573
- var previewCodeLines = previewCodeStr . split ( '\n' ) ;
574
- var previewCode = previewCodeLines . pop ( ) ;
634
+ var previewCode = previewCodeStr ;
635
+ if ( previewCodeStr . includes ( '\n' ) === true ) {
636
+ let previewCodeLines = previewCodeStr . split ( '\n' ) ;
637
+ previewCode = previewCodeLines . pop ( ) ;
638
+ }
575
639
this . setCmValue ( 'previewCode' , previewCode ) ;
576
640
}
577
641
@@ -1273,12 +1337,11 @@ define([
1273
1337
}
1274
1338
1275
1339
var that = this ;
1276
- var tempObj = this . state . tempObj ;
1277
- var lines = this . state . lines ;
1340
+ let { tempObj, lines, indexList } = this . state ;
1278
1341
var prevLines = 0 ;
1279
1342
var scrollPos = - 1 ;
1280
1343
if ( more ) {
1281
- prevLines = that . state . indexList . length ;
1344
+ prevLines = indexList . length ;
1282
1345
scrollPos = $ ( this . wrapSelector ( '.vp-fe-table' ) ) . scrollTop ( ) ;
1283
1346
}
1284
1347
0 commit comments