UNPKG

@phroun/paged-buffer

Version:

High-performance buffer system for editing massive files with intelligent memory management and undo/redo capabilities

214 lines 7.35 kB
/** * Enhanced Buffer Undo/Redo System with Line and Marks Integration */ export class BufferUndoSystem { constructor(buffer: any, maxUndoLevels?: number); buffer: any; maxUndoLevels: number; undoStack: any[]; redoStack: any[]; activeTransaction: OperationTransaction | null; mergeTimeWindow: number; mergePositionWindow: number; isUndoing: boolean; groupIdCounter: number; clockFunction: () => number; /** * Configure the undo system * @param {Object} config - Configuration options */ configure(config: Object): void; /** * Set custom clock function (for testing) * @param {Function} clockFn - Function that returns current time */ setClock(clockFn: Function): void; /** * Get current time from clock function * @returns {number} - Current timestamp */ getClock(): number; /** * Generate unique group ID * @returns {string} - Unique group ID */ _generateGroupId(): string; /** * CRITICAL FIX: Capture current marks state for snapshot BEFORE any operation recording * This must be called by buffer operations BEFORE they execute * @returns {Array} - Current marks snapshot */ captureCurrentMarksState(): any[]; /** * Record an insert operation with enhanced tracking * @param {number} position - Insert position * @param {Buffer} data - Inserted data * @param {number} timestamp - Optional timestamp (defaults to current time) * @param {Array} preOpMarksSnapshot - Pre-operation marks snapshot * @returns {BufferOperation} - The created operation */ recordInsert(position: number, data: Buffer, timestamp?: number, preOpMarksSnapshot?: any[]): BufferOperation; /** * Record a delete operation with enhanced tracking * @param {number} position - Delete position * @param {Buffer} deletedData - Data that was deleted * @param {number} timestamp - Optional timestamp (defaults to current time) * @param {Array} preOpMarksSnapshot - Pre-operation marks snapshot * @returns {BufferOperation} - The created operation */ recordDelete(position: number, deletedData: Buffer, timestamp?: number, preOpMarksSnapshot?: any[]): BufferOperation; /** * Record an overwrite operation with enhanced tracking * @param {number} position - Overwrite position * @param {Buffer} newData - New data * @param {Buffer} originalData - Original data that was overwritten * @param {number} timestamp - Optional timestamp (defaults to current time) * @param {Array} preOpMarksSnapshot - Pre-operation marks snapshot * @returns {BufferOperation} - The created operation */ recordOverwrite(position: number, newData: Buffer, originalData: Buffer, timestamp?: number, preOpMarksSnapshot?: any[]): BufferOperation; /** * Enhanced operation recording with marks and lines tracking - FIXED SNAPSHOT TIMING * @param {BufferOperation} operation - Operation to record * @param {Array} preOpMarksSnapshot - Pre-operation marks snapshot * @private */ private _recordOperation; /** * Helper method to get distance between operations */ _getOperationDistance(op1: any, op2: any): any; /** * More conservative contiguous operation detection */ _areContiguousOperations(op1: any, op2: any): boolean; /** * Begin a new transaction with state tracking * @param {string} name - Transaction name * @param {Object} options - Transaction options */ beginUndoTransaction(name: string, options?: Object): void; /** * Commit the current transaction with enhanced state tracking * @param {string} finalName - Optional final name for the group * @returns {boolean} - True if transaction was committed */ commitUndoTransaction(finalName?: string): boolean; /** * Enhanced rollback with marks and lines restoration * @returns {Promise<boolean>} - True if transaction was rolled back */ rollbackUndoTransaction(): Promise<boolean>; /** * Check if currently in a transaction * @returns {boolean} - True if in transaction */ inTransaction(): boolean; /** * Get current transaction info * @returns {Object|null} - Transaction info or null */ getCurrentTransaction(): Object | null; /** * Enhanced undo with marks and lines restoration * @returns {Promise<boolean>} - True if successful */ undo(): Promise<boolean>; /** * Enhanced redo with marks and lines restoration * @returns {Promise<boolean>} - True if successful */ redo(): Promise<boolean>; /** * CORRECTED: Restore marks state from snapshot using virtual addresses * @param {Array} marksSnapshot - Marks to restore (virtual address format) * @private */ private _restoreMarksState; /** * Undo a single operation using Virtual Page Manager with enhanced tracking * @param {BufferOperation} operation - Operation to undo * @private */ private _undoOperationVPM; _redoOperationVPM(operation: any): Promise<void>; /** * Check if undo is available * @returns {boolean} - True if undo is available */ canUndo(): boolean; /** * Check if redo is available * @returns {boolean} - True if redo is available */ canRedo(): boolean; /** * Get enhanced undo/redo statistics * @returns {Object} - Statistics */ getStats(): Object; /** * Clear all undo/redo history */ clear(): void; /** * Get enhanced debug information * @returns {Object} - Debug info */ getDebugInfo(): Object; } /** * Groups related operations together for undo/redo */ export class OperationGroup { constructor(id: any, name?: null); id: any; name: any; operations: any[]; timestamp: number; isFromTransaction: boolean; marksSnapshot: any[] | null; linesSnapshot: number | null; /** * Calculate total memory usage of this group * @returns {number} - Estimated memory usage in bytes */ getMemoryUsage(): number; /** * Set marks snapshot for this group * @param {Array} marks - Current marks state */ setMarksSnapshot(marks: any[]): void; /** * Set lines snapshot for this group * @param {number} lineCount - Current line count */ setLinesSnapshot(lineCount: number): void; } /** * Transaction for grouping operations */ export class OperationTransaction { constructor(name: any, options?: {}); name: any; operations: any[]; startTime: number; options: {}; initialMarksSnapshot: any[] | null; initialLinesSnapshot: number | null; /** * Set initial state snapshots * @param {Array} marks - Initial marks state * @param {number} lineCount - Initial line count */ setInitialState(marks: any[], lineCount: number): void; /** * Get info about this transaction * @returns {Object} - Transaction info */ getInfo(): Object; } import { BufferOperation } from "./buffer-operation"; import { OperationType } from "./buffer-operation"; export { BufferOperation, OperationType }; //# sourceMappingURL=undo-system.d.ts.map