You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							43 lines
						
					
					
						
							798 B
						
					
					
				
			
		
		
	
	
							43 lines
						
					
					
						
							798 B
						
					
					
				| import { Transaction } from 'prosemirror-state'
 | |
| 
 | |
| export interface TrackerResult {
 | |
|   position: number,
 | |
|   deleted: boolean,
 | |
| }
 | |
| 
 | |
| export class Tracker {
 | |
| 
 | |
|   transaction: Transaction
 | |
| 
 | |
|   currentStep: number
 | |
| 
 | |
|   constructor(transaction: Transaction) {
 | |
|     this.transaction = transaction
 | |
|     this.currentStep = this.transaction.steps.length
 | |
|   }
 | |
| 
 | |
|   map(position: number): TrackerResult {
 | |
|     let deleted = false
 | |
| 
 | |
|     const mappedPosition = this.transaction.steps
 | |
|       .slice(this.currentStep)
 | |
|       .reduce((newPosition, step) => {
 | |
|         const mapResult = step
 | |
|           .getMap()
 | |
|           .mapResult(newPosition)
 | |
| 
 | |
|         if (mapResult.deleted) {
 | |
|           deleted = true
 | |
|         }
 | |
| 
 | |
|         return mapResult.pos
 | |
|       }, position)
 | |
| 
 | |
|     return {
 | |
|       position: mappedPosition,
 | |
|       deleted,
 | |
|     }
 | |
|   }
 | |
| 
 | |
| }
 |