@phroun/paged-buffer
Version:
High-performance buffer system for editing massive files with intelligent memory management and undo/redo capabilities
185 lines • 6.66 kB
TypeScript
/**
* @fileoverview Line and Marks Manager - Page coordinate-based marks with CORRECTED logic
* @description Manages line positions and named marks using page coordinates for efficiency
* @author Jeffrey R. Day
* @version 2.1.1 - Fixed mark update logic for deletions and page operations
*/
/// <reference types="node" />
/// <reference types="node" />
import { type IVirtualPageManager, type ILineAndMarksManager, type MarkTuple, type RelativeMarkTuple, type LineCharPosition, type LineAndMarksManagerMemoryStats } from '../types/common';
/**
* Represents the result of line-related operations
*/
declare class LineOperationResult {
lineNumber: number;
byteStart: number;
byteEnd: number;
length: number;
marks: MarkTuple[];
isExact: boolean;
constructor(lineNumber: number, byteStart: number, byteEnd: number, marks?: MarkTuple[], isExact?: boolean);
}
/**
* Represents extracted content with marks - FIXED to use tuples consistently
*/
declare class ExtractedContent {
data: Buffer;
marks: RelativeMarkTuple[];
constructor(data: Buffer, marks?: RelativeMarkTuple[]);
}
/**
* Page coordinate-based marks and line manager
*/
declare class LineAndMarksManager implements ILineAndMarksManager {
private vpm;
private globalMarks;
private pageToMarks;
constructor(virtualPageManager: IVirtualPageManager);
/**
* Convert virtual address to page coordinates
*/
private _virtualToPageCoord;
/**
* Convert page coordinates to virtual address
*/
private _pageCoordToVirtual;
/**
* Set mark using page coordinates
*/
private _setMarkByCoord;
/**
* Remove mark from page index
*/
private _removeFromPageIndex;
/**
* Helper method to update mark coordinate and page index
*/
private _updateMarkCoordinate;
/**
* Handle page split - transfer marks to appropriate pages
*/
handlePageSplit(originalPageKey: string, newPageKey: string, splitOffset: number): void;
/**
* Handle page merge - transfer marks from absorbed page
*/
handlePageMerge(absorbedPageKey: string, targetPageKey: string, insertOffset: number): void;
/**
* Validate and clean up orphaned marks
*/
validateAndCleanupMarks(): string[];
/**
* Find the next page after the given page
*/
private _findNextPage;
/**
* Set a named mark at a virtual address
*/
setMark(markName: string, virtualAddress: number): void;
/**
* Get the virtual address of a named mark
*/
getMark(markName: string): number | null;
/**
* Remove a named mark
*/
removeMark(markName: string): boolean;
/**
* Get all marks between two virtual addresses
*/
getMarksInRange(startAddress: number, endAddress: number): MarkTuple[];
/**
* Get all marks in the buffer
*/
getAllMarks(): MarkTuple[];
/**
* Get information about marks in content that will be deleted
* This reports what marks were in the deleted content (for paste operations)
* but does NOT remove the marks - they get consolidated to deletion start
*/
getMarksInDeletedContent(startAddress: number, endAddress: number): RelativeMarkTuple[];
/**
* Remove marks from a range entirely (for true extraction/cut operations)
* This actually removes marks from the buffer - used when marks should disappear
*/
removeMarksFromRange(startAddress: number, endAddress: number): RelativeMarkTuple[];
/**
* Insert marks from relative positions (for insert operations)
*/
insertMarksFromRelative(insertAddress: number, marks: RelativeMarkTuple[]): void;
/**
* Get all marks as a key-value object with virtual addresses (for persistence)
*/
getAllMarksForPersistence(): Record<string, number>;
/**
* Set marks from a key-value object (for persistence)
* Updates/overwrites conflicting marks, retains others
*/
setMarksFromPersistence(marksObject: Record<string, number>): void;
/**
* Clear all marks
*/
clearAllMarks(): void;
/**
* Enhanced getBytes that includes marks in the result
*/
getBytesWithMarks(start: number, end: number, includeMarks?: boolean): Promise<Buffer | ExtractedContent>;
/**
* CORRECTED: Enhanced insertBytes - handles marks correctly with page operations
*/
insertBytesWithMarks(position: number, data: Buffer, marks?: RelativeMarkTuple[]): Promise<void>;
/**
* CORRECTED: Enhanced deleteBytes - reports marks in deleted content but consolidates them
*/
deleteBytesWithMarks(start: number, end: number, reportMarks?: boolean): Promise<ExtractedContent>;
/**
* Enhanced overwriteBytes with marks support
*/
overwriteBytesWithMarks(position: number, data: Buffer, marks?: RelativeMarkTuple[]): Promise<ExtractedContent>;
/**
* CORRECTED: Update marks after a modification using virtual addresses
* This method handles logical mark movement for content changes
*/
updateMarksAfterModification(virtualStart: number, deletedBytes: number, insertedBytes: number): void;
/**
* Invalidate line caches (called when buffer content changes)
*/
invalidateLineCaches(): void;
/**
* Invalidate line caches in pages (called when buffer content changes)
*/
invalidatePageLineCaches(): void;
/**
* Ensure page containing address is loaded (ASYNC)
*/
seekAddress(address: number): Promise<boolean>;
/**
* Get the total number of lines in the buffer (SYNCHRONOUS)
*/
getTotalLineCount(): number;
/**
* Get line information by line number (SYNCHRONOUS)
*/
getLineInfo(lineNumber: number): LineOperationResult | null;
/**
* Get information about multiple lines at once (SYNCHRONOUS)
*/
getMultipleLines(startLine: number, endLine: number): LineOperationResult[];
/**
* Convert virtual byte address to line number (SYNCHRONOUS)
*/
getLineNumberFromAddress(virtualAddress: number): number;
/**
* Convert line/character position to absolute byte position (SYNCHRONOUS)
*/
lineCharToBytePosition(pos: LineCharPosition): number;
/**
* Convert absolute byte position to line/character position (SYNCHRONOUS)
*/
byteToLineCharPosition(bytePos: number): LineCharPosition;
/**
* Get memory usage statistics
*/
getMemoryStats(): LineAndMarksManagerMemoryStats;
}
export { LineAndMarksManager, LineOperationResult, ExtractedContent };
//# sourceMappingURL=line-marks-manager.d.ts.map