@@ -25,13 +25,12 @@ export interface IWhitespaceChangeAccessor {
2525 removeWhitespace ( id : string ) : void ;
2626}
2727
28- interface IPendingInsert { id : string ; afterLineNumber : number ; ordinal : number ; heightInPx : number ; minWidth : number ; }
2928interface IPendingChange { id : string ; newAfterLineNumber : number ; newHeight : number ; }
3029interface IPendingRemove { id : string ; }
3130
3231class PendingChanges {
3332 private _hasPending : boolean ;
34- private _inserts : IPendingInsert [ ] ;
33+ private _inserts : InternalWhitespace [ ] ;
3534 private _changes : IPendingChange [ ] ;
3635 private _removes : IPendingRemove [ ] ;
3736
@@ -42,7 +41,7 @@ class PendingChanges {
4241 this . _removes = [ ] ;
4342 }
4443
45- public insert ( x : IPendingInsert ) : void {
44+ public insert ( x : InternalWhitespace ) : void {
4645 this . _hasPending = true ;
4746 this . _inserts . push ( x ) ;
4847 }
@@ -210,7 +209,7 @@ export class LinesLayout {
210209 minWidth = minWidth | 0 ;
211210
212211 const id = this . _instanceId + ( ++ this . _lastWhitespaceId ) ;
213- this . _pendingChanges . insert ( { id, afterLineNumber, ordinal, heightInPx, minWidth } ) ;
212+ this . _pendingChanges . insert ( new InternalWhitespace ( id , afterLineNumber , ordinal , heightInPx , minWidth ) ) ;
214213 return id ;
215214 // return this._insertWhitespace(afterLineNumber, ordinal, heightInPx, minWidth);
216215 } ,
@@ -232,16 +231,23 @@ export class LinesLayout {
232231 }
233232 }
234233
235- public _commitPendingChanges ( inserts : IPendingInsert [ ] , changes : IPendingChange [ ] , removes : IPendingRemove [ ] ) : void {
234+ public _commitPendingChanges ( inserts : InternalWhitespace [ ] , changes : IPendingChange [ ] , removes : IPendingRemove [ ] ) : void {
235+ // const magnitude = inserts.length + changes.length + removes.length;
236+ // if (magnitude === 1) {
237+ // // when only one thing
236238 for ( const insert of inserts ) {
237- this . _insertWhitespace ( insert . id , insert . afterLineNumber , insert . ordinal , insert . heightInPx , insert . minWidth ) ;
239+ this . _insertWhitespace ( insert ) ;
238240 }
239241 for ( const change of changes ) {
240242 this . _changeOneWhitespace ( change . id , change . newAfterLineNumber , change . newHeight ) ;
241243 }
242244 for ( const remove of removes ) {
243245 this . _removeWhitespace ( remove . id ) ;
244246 }
247+ return ;
248+ // }
249+
250+ // console.log(`magnitude: ${magnitude} -- inserts: ${inserts.length}, changes: ${changes.length}, removes: ${removes.length}`);
245251 // console.log(`TODO: `, inserts, changes, removes);
246252 }
247253
@@ -251,21 +257,10 @@ export class LinesLayout {
251257 }
252258 }
253259
254- /**
255- * Insert a new whitespace of a certain height after a line number.
256- * The whitespace has a "sticky" characteristic.
257- * Irrespective of edits above or below `afterLineNumber`, the whitespace will follow the initial line.
258- *
259- * @param afterLineNumber The conceptual position of this whitespace. The whitespace will follow this line as best as possible even when deleting/inserting lines above/below.
260- * @param heightInPx The height of the whitespace, in pixels.
261- * @return An id that can be used later to mutate or delete the whitespace
262- */
263- private _insertWhitespace ( id : string , afterLineNumber : number , ordinal : number , heightInPx : number , minWidth : number ) : string {
264- const whitespace = new InternalWhitespace ( id , afterLineNumber , ordinal , heightInPx , minWidth ) ;
260+ private _insertWhitespace ( whitespace : InternalWhitespace ) : void {
265261 const insertionIndex = LinesLayout . findInsertionIndex ( this . _arr , whitespace . afterLineNumber , whitespace . ordinal ) ;
266262 this . _insertWhitespaceAtIndex ( insertionIndex , whitespace ) ;
267263 this . _minWidth = - 1 ; /* marker for not being computed */
268- return id ;
269264 }
270265
271266 private _insertWhitespaceAtIndex ( insertIndex : number , whitespace : InternalWhitespace ) : void {
@@ -283,9 +278,6 @@ export class LinesLayout {
283278 this . _prefixSumValidIndex = Math . min ( this . _prefixSumValidIndex , insertIndex - 1 ) ;
284279 }
285280
286- /**
287- * Change properties associated with a certain whitespace.
288- */
289281 private _changeOneWhitespace ( id : string , newAfterLineNumber : number , newHeight : number ) : void {
290282 if ( this . _whitespaceId2Index . hasOwnProperty ( id ) ) {
291283 const index = this . _whitespaceId2Index [ id ] ;
@@ -311,12 +303,6 @@ export class LinesLayout {
311303 }
312304 }
313305
314- /**
315- * Remove an existing whitespace.
316- *
317- * @param id The whitespace to remove
318- * @return Returns true if the whitespace is found and it is removed.
319- */
320306 private _removeWhitespace ( id : string ) : void {
321307 if ( this . _whitespaceId2Index . hasOwnProperty ( id ) ) {
322308 const index = this . _whitespaceId2Index [ id ] ;
0 commit comments