@@ -63,12 +63,12 @@ export class TimeTravelActions extends CodeEditorActions<TimeTravelState> {
63
63
private docpath : string ;
64
64
private docext : string ;
65
65
private syncpath : string ;
66
- public syncdoc ?: SyncDoc ;
66
+ syncdoc ?: SyncDoc ;
67
67
private first_load : boolean = true ;
68
- public ambient_actions ?: CodeEditorActions ;
68
+ ambient_actions ?: CodeEditorActions ;
69
69
private gitTimestampToHash : { [ t : number ] : string } = { } ;
70
70
71
- public _init2 ( ) : void {
71
+ _init2 ( ) : void {
72
72
const { head, tail } = path_split ( this . path ) ;
73
73
this . docpath = tail . slice ( 1 , tail . length - EXTENSION . length ) ;
74
74
if ( head != "" ) {
@@ -90,19 +90,19 @@ export class TimeTravelActions extends CodeEditorActions<TimeTravelState> {
90
90
this . updateGitVersions ( ) ;
91
91
}
92
92
93
- public _raw_default_frame_tree ( ) : FrameTree {
93
+ _raw_default_frame_tree ( ) : FrameTree {
94
94
return { type : "time_travel" } ;
95
95
}
96
96
97
- private async init_syncdoc ( ) : Promise < void > {
97
+ private init_syncdoc = async ( ) : Promise < void > = > {
98
98
const persistent = this . docext == "ipynb" || this . docext == "sagews" ; // ugly for now (?)
99
99
this . syncdoc = await webapp_client . sync_client . open_existing_sync_document ( {
100
100
project_id : this . project_id ,
101
101
path : this . syncpath ,
102
102
persistent,
103
103
} ) ;
104
104
if ( this . syncdoc == null ) return ;
105
- this . syncdoc . on ( "change" , debounce ( this . syncdoc_changed . bind ( this ) , 1000 ) ) ;
105
+ this . syncdoc . on ( "change" , debounce ( this . syncdoc_changed , 1000 ) ) ;
106
106
if ( this . syncdoc . get_state ( ) != "ready" ) {
107
107
await once ( this . syncdoc , "ready" ) ;
108
108
}
@@ -115,7 +115,7 @@ export class TimeTravelActions extends CodeEditorActions<TimeTravelState> {
115
115
loading : false ,
116
116
has_full_history : this . syncdoc . has_full_history ( ) ,
117
117
} ) ;
118
- }
118
+ } ;
119
119
120
120
init_frame_tree = ( ) => {
121
121
this . ensureSelectedVersionsAreConsistent ( ) ;
@@ -166,7 +166,7 @@ export class TimeTravelActions extends CodeEditorActions<TimeTravelState> {
166
166
}
167
167
} ;
168
168
169
- public async load_full_history ( ) : Promise < void > {
169
+ load_full_history = async ( ) : Promise < void > = > {
170
170
if (
171
171
this . store . get ( "has_full_history" ) ||
172
172
this . syncdoc == null ||
@@ -176,9 +176,9 @@ export class TimeTravelActions extends CodeEditorActions<TimeTravelState> {
176
176
await this . syncdoc . load_full_history ( ) ; // todo -- error reporting ...?
177
177
this . setState ( { has_full_history : true } ) ;
178
178
this . syncdoc_changed ( ) ; // load new versions list.
179
- }
179
+ } ;
180
180
181
- private syncdoc_changed ( ) : void {
181
+ private syncdoc_changed = ( ) : void => {
182
182
if ( this . syncdoc == null ) return ;
183
183
if ( this . syncdoc ?. get_state ( ) != "ready" ) {
184
184
return ;
@@ -197,28 +197,28 @@ export class TimeTravelActions extends CodeEditorActions<TimeTravelState> {
197
197
this . first_load = false ;
198
198
this . ensureSelectedVersionsAreConsistent ( { versions } ) ;
199
199
}
200
- }
200
+ } ;
201
201
202
202
// For each store version in a frame node, check to see
203
203
// if the Date changes from the current versions to the new
204
204
// ones and if so, fix it. We do this because if you're looking
205
205
// at time t at position p, and somebody inserts a new version
206
206
// before position p ... then suddenly position p is no longer
207
207
// time t, which would be confusing.
208
- private ensure_versions_are_stable ( new_versions ) : void {
208
+ private ensure_versions_are_stable = ( new_versions ) : void => {
209
209
// TODO
210
210
new_versions = new_versions ;
211
- }
211
+ } ;
212
212
213
213
// Get the given version of the document.
214
- public get_doc ( version : Date ) : Document | undefined {
214
+ get_doc = ( version : Date ) : Document | undefined => {
215
215
if ( this . syncdoc == null ) return ;
216
216
const state = this . syncdoc . get_state ( ) ;
217
217
if ( state != "ready" ) return ;
218
218
return this . syncdoc . version ( version ) ;
219
- }
219
+ } ;
220
220
221
- public get_account_ids ( version0 : number , version1 : number ) : string [ ] {
221
+ get_account_ids = ( version0 : number , version1 : number ) : string [ ] => {
222
222
if ( this . syncdoc == null ) return [ ] ;
223
223
const versions = this . store . get ( "versions" ) ;
224
224
if ( versions == null || versions . size == 0 ) return [ ] ;
@@ -234,16 +234,16 @@ export class TimeTravelActions extends CodeEditorActions<TimeTravelState> {
234
234
}
235
235
}
236
236
return keys ( account_ids ) ;
237
- }
237
+ } ;
238
238
239
- private get_frame_node_global ( id : string ) {
239
+ private getFrameNodeGlobal = ( id : string ) => {
240
240
for ( const actions of [ this , this . ambient_actions ] ) {
241
241
if ( actions == null ) continue ;
242
242
const node = actions . _get_frame_node ( id ) ;
243
243
if ( node != null ) return node ;
244
244
}
245
245
throw Error ( `BUG -- no node with id ${ id } ` ) ;
246
- }
246
+ } ;
247
247
248
248
set_version = ( id : string , version : number ) : void => {
249
249
for ( const actions of [ this , this . ambient_actions ] ) {
@@ -270,17 +270,19 @@ export class TimeTravelActions extends CodeEditorActions<TimeTravelState> {
270
270
}
271
271
} ;
272
272
273
- public step ( id : string , delta : number ) : void {
274
- const node = this . get_frame_node_global ( id ) ;
273
+ step = ( id : string , delta : number ) : void => {
274
+ const node = this . getFrameNodeGlobal ( id ) ;
275
275
if ( node . get ( "changes_mode" ) ) {
276
- this . set_versions (
276
+ this . setVersions (
277
277
id ,
278
278
node . get ( "version0" ) + delta ,
279
279
node . get ( "version1" ) + delta ,
280
280
) ;
281
281
return ;
282
282
}
283
- const versions = this . store . get ( "versions" ) ;
283
+ const versions = node . get ( "git_mode" )
284
+ ? this . store . get ( "git_versions" )
285
+ : this . store . get ( "versions" ) ;
284
286
if ( versions == null || versions . size == 0 ) return ;
285
287
let version = node . get ( "version" ) ;
286
288
if ( version == null ) {
@@ -293,9 +295,9 @@ export class TimeTravelActions extends CodeEditorActions<TimeTravelState> {
293
295
version += versions . size ;
294
296
}
295
297
this . set_version ( id , version ) ;
296
- }
298
+ } ;
297
299
298
- public set_changes_mode ( id : string , changes_mode : boolean ) : void {
300
+ set_changes_mode = ( id : string , changes_mode : boolean ) : void => {
299
301
for ( const actions of [ this , this . ambient_actions ] ) {
300
302
if ( actions == null ) continue ;
301
303
const node = actions . _get_frame_node ( id ) ;
@@ -320,9 +322,9 @@ export class TimeTravelActions extends CodeEditorActions<TimeTravelState> {
320
322
}
321
323
return ;
322
324
}
323
- }
325
+ } ;
324
326
325
- public setTextMode ( id : string , text_mode : boolean ) : void {
327
+ setTextMode = ( id : string , text_mode : boolean ) : void => {
326
328
for ( const actions of [ this , this . ambient_actions ] ) {
327
329
if ( actions == null ) continue ;
328
330
const node = actions . _get_frame_node ( id ) ;
@@ -331,9 +333,9 @@ export class TimeTravelActions extends CodeEditorActions<TimeTravelState> {
331
333
actions . set_frame_tree ( { id, text_mode } ) ;
332
334
break ;
333
335
}
334
- }
336
+ } ;
335
337
336
- public setGitMode ( id : string , git_mode : boolean ) : void {
338
+ setGitMode = ( id : string , git_mode : boolean ) : void => {
337
339
for ( const actions of [ this , this . ambient_actions ] ) {
338
340
if ( actions == null ) continue ;
339
341
const node = actions . _get_frame_node ( id ) ;
@@ -343,44 +345,61 @@ export class TimeTravelActions extends CodeEditorActions<TimeTravelState> {
343
345
break ;
344
346
}
345
347
this . updateGitVersions ( ) ;
346
- }
348
+ } ;
347
349
348
- public set_versions ( id : string , version0 : number , version1 : number ) : void {
350
+ setVersions = ( id : string , version0 : number , version1 : number ) : void => {
349
351
for ( const actions of [ this , this . ambient_actions ] ) {
350
- if ( actions == null || actions . _get_frame_node ( id ) == null ) continue ;
351
- const versions = this . store . get ( "versions" ) ;
352
+ const node = actions ?. _get_frame_node ( id ) ;
353
+ if ( node == null ) {
354
+ continue ;
355
+ }
356
+ const versions = node . get ( "git_mode" )
357
+ ? this . store . get ( "git_versions" )
358
+ : this . store . get ( "versions" ) ;
359
+ if ( versions == null ) {
360
+ // not configured.
361
+ return ;
362
+ }
352
363
if ( version0 >= version1 ) {
353
364
version0 = version1 - 1 ;
354
365
}
355
- if ( version0 >= versions . size ) version0 = versions . size - 1 ;
356
- if ( version0 < 0 ) version0 = 0 ;
357
- if ( version1 >= versions . size ) version1 = versions . size - 1 ;
358
- if ( version1 < 0 ) version1 = 0 ;
359
- actions . set_frame_tree ( { id, version0, version1 } ) ;
366
+ if ( version0 >= versions . size ) {
367
+ version0 = versions . size - 1 ;
368
+ }
369
+ if ( version0 < 0 ) {
370
+ version0 = 0 ;
371
+ }
372
+ if ( version1 >= versions . size ) {
373
+ version1 = versions . size - 1 ;
374
+ }
375
+ if ( version1 < 0 ) {
376
+ version1 = 0 ;
377
+ }
378
+ actions ?. set_frame_tree ( { id, version0, version1 } ) ;
360
379
return ;
361
380
}
362
- }
381
+ } ;
363
382
364
- public async open_file ( ) : Promise < void > {
383
+ open_file = async ( ) : Promise < void > = > {
365
384
const actions = this . redux . getProjectActions ( this . project_id ) ;
366
385
await actions . open_file ( { path : this . docpath , foreground : true } ) ;
367
- }
386
+ } ;
368
387
369
388
// Revert the live version of the document to a specific version */
370
- public async revert ( version : Date ) : Promise < void > {
389
+ revert = async ( version : Date ) : Promise < void > = > {
371
390
if ( this . syncdoc == null ) return ;
372
391
this . syncdoc . revert ( version ) ;
373
392
this . syncdoc . commit ( ) ;
374
393
await this . open_file ( ) ;
375
394
if ( this . syncdoc == null ) return ;
376
395
this . syncdoc . emit ( "change" ) ;
377
- }
396
+ } ;
378
397
379
- public open_snapshots ( ) : void {
398
+ open_snapshots = ( ) : void => {
380
399
this . redux . getProjectActions ( this . project_id ) . open_directory ( ".snapshots" ) ;
381
- }
400
+ } ;
382
401
383
- public async export ( ) : Promise < string > {
402
+ exportEditHistory = async ( ) : Promise < string > = > {
384
403
const path = await export_to_json (
385
404
this . syncdoc ,
386
405
this . docpath ,
@@ -389,7 +408,7 @@ export class TimeTravelActions extends CodeEditorActions<TimeTravelState> {
389
408
const actions = this . redux . getProjectActions ( this . project_id ) ;
390
409
await actions . open_file ( { path, foreground : true } ) ;
391
410
return path ;
392
- }
411
+ } ;
393
412
394
413
// We have not implemented any way to do programmatical_goto_line this for time travel yet.
395
414
// It will be very interesting and useful, because it will allow for
0 commit comments