@phroun/paged-buffer
Version:
High-performance buffer system for editing massive files with intelligent memory management and undo/redo capabilities
275 lines • 11.3 kB
TypeScript
export type MarkTuple = Array<string | number>;
export type RelativeMarkTuple = Array<string | number>;
/**
* Page coordinate-based marks and line manager
*/
export class LineAndMarksManager {
constructor(virtualPageManager: any);
vpm: any;
globalMarks: Map<any, any>;
pageToMarks: Map<any, any>;
/**
* Convert virtual address to page coordinates
* @param {number} virtualAddress - Virtual buffer address
* @returns {Array} - [pageId, offset]
* @private
*/
private _virtualToPageCoord;
/**
* Convert page coordinates to virtual address
* @param {string} pageId - Page identifier
* @param {number} offset - Offset within page
* @returns {number} - Virtual buffer address
* @private
*/
private _pageCoordToVirtual;
/**
* Set mark using page coordinates
* @param {string} markName - Name of the mark
* @param {string} pageId - Page identifier
* @param {number} offset - Offset within page
* @private
*/
private _setMarkByCoord;
/**
* Remove mark from page index
* @param {string} markName - Name of the mark
* @param {string} pageId - Page identifier
* @private
*/
private _removeFromPageIndex;
/**
* Get all mark names in a specific page
* @param {string} pageId - Page identifier
* @returns {Set<string>} - Set of mark names
* @private
*/
private _getMarkNamesInPage;
/**
* Helper method to update mark coordinate and page index
* @param {string} markName - Name of the mark
* @param {Array} coord - Coordinate array to update in place [pageId, offset]
* @param {Array} newCoord - New coordinate [pageId, offset]
* @private
*/
private _updateMarkCoordinate;
/**
* Handle page split - transfer marks to appropriate pages
* @param {string} originalPageId - Original page being split
* @param {string} newPageId - New page created from split
* @param {number} splitOffset - Offset within original page where split occurred
*/
handlePageSplit(originalPageId: string, newPageId: string, splitOffset: number): void;
/**
* Handle page merge - transfer marks from absorbed page
* @param {string} absorbedPageId - Page being absorbed/deleted
* @param {string} targetPageId - Page absorbing the content
* @param {number} insertOffset - Offset in target page where absorbed content starts
*/
handlePageMerge(absorbedPageId: string, targetPageId: string, insertOffset: number): void;
/**
* Validate and clean up orphaned marks
* @returns {Array<string>} - Names of orphaned marks that were removed
*/
validateAndCleanupMarks(): Array<string>;
/**
* Find the next page after the given page
* @param {PageDescriptor} currentPage - Current page descriptor
* @returns {PageDescriptor|null} - Next page or null
* @private
*/
private _findNextPage;
/**
* Set a named mark at a virtual address
* @param {string} markName - Name of the mark
* @param {number} virtualAddress - Virtual buffer address
*/
setMark(markName: string, virtualAddress: number): void;
/**
* Get the virtual address of a named mark
* @param {string} markName - Name of the mark
* @returns {number|null} - Virtual address or null if not found
*/
getMark(markName: string): number | null;
/**
* Remove a named mark
* @param {string} markName - Name of the mark
* @returns {boolean} - True if mark was found and removed
*/
removeMark(markName: string): boolean;
/**
* Get all marks between two virtual addresses
* @param {number} startAddress - Start address (inclusive)
* @param {number} endAddress - End address (inclusive)
* @returns {Array<MarkTuple>} - Name and absolute address of each mark
*/
getMarksInRange(startAddress: number, endAddress: number): Array<MarkTuple>;
/**
* Get all marks in the buffer
* @returns {Array<MarkTuple>} - Name and absolute address of all marks
*/
getAllMarks(): Array<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
* @param {number} startAddress - Start address
* @param {number} endAddress - End address
* @returns {Array<RelativeMarkTuple>} - Relative mark info for deleted content
*/
getMarksInDeletedContent(startAddress: number, endAddress: number): Array<RelativeMarkTuple>;
/**
* Remove marks from a range entirely (for true extraction/cut operations)
* This actually removes marks from the buffer - used when marks should disappear
* @param {number} startAddress - Start address
* @param {number} endAddress - End address
* @returns {Array<RelativeMarkTuple>} - Relative info for removed marks
*/
removeMarksFromRange(startAddress: number, endAddress: number): Array<RelativeMarkTuple>;
/**
* Insert marks from relative positions (for insert operations)
* @param {number} insertAddress - Address where content was inserted
* @param {Array<RelativeMarkTuple>} marks - Relative marks to insert
*/
insertMarksFromRelative(insertAddress: number, marks: Array<RelativeMarkTuple>): void;
/**
* Get all marks as a key-value object with virtual addresses (for persistence)
* @returns {Object} - Object mapping mark names to virtual addresses
*/
getAllMarksForPersistence(): Object;
/**
* Set marks from a key-value object (for persistence)
* Updates/overwrites conflicting marks, retains others
* @param {Object} marksObject - Object mapping mark names to virtual addresses
*/
setMarksFromPersistence(marksObject: Object): void;
/**
* Clear all marks
*/
clearAllMarks(): void;
/**
* Enhanced getBytes that includes marks in the result
* @param {number} start - Start address
* @param {number} end - End address
* @param {boolean} includeMarks - Whether to include marks in result
* @returns {Promise<Buffer|ExtractedContent>} - Data or data with marks
*/
getBytesWithMarks(start: number, end: number, includeMarks?: boolean): Promise<Buffer | ExtractedContent>;
/**
* CORRECTED: Enhanced insertBytes - handles marks correctly with page operations
* @param {number} position - Insert position
* @param {Buffer} data - Data to insert
* @param {Array<RelativeMarkTuple>} marks -Relative marks to insert
*/
insertBytesWithMarks(position: number, data: Buffer, marks?: Array<RelativeMarkTuple>): Promise<void>;
/**
* CORRECTED: Enhanced deleteBytes - reports marks in deleted content but consolidates them
* @param {number} start - Start address
* @param {number} end - End address
* @param {boolean} reportMarks - Whether to report marks that were in deleted content
* @returns {Promise<ExtractedContent>} - Deleted data with optional marks report
*/
deleteBytesWithMarks(start: number, end: number, reportMarks?: boolean): Promise<ExtractedContent>;
/**
* Enhanced overwriteBytes with marks support
* @param {number} position - Overwrite position
* @param {Buffer} data - New data
* @param {Array<RelativeMarkTuple>} marks - Relative marks to insert
* @returns {Promise<ExtractedContent>} - Overwritten data with marks info
*/
overwriteBytesWithMarks(position: number, data: Buffer, marks?: Array<RelativeMarkTuple>): Promise<ExtractedContent>;
/**
* CORRECTED: Update marks after a modification using virtual addresses
* This method handles logical mark movement for content changes
* @param {number} virtualStart - Start of modification
* @param {number} deletedBytes - Bytes deleted
* @param {number} insertedBytes - Bytes inserted
*/
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)
* @param {number} address - Byte address to load
* @returns {Promise<boolean>} - True if page was loaded successfully
*/
seekAddress(address: number): Promise<boolean>;
/**
* Get the total number of lines in the buffer (SYNCHRONOUS)
* @returns {number} - Total line count
*/
getTotalLineCount(): number;
/**
* Get line information by line number (SYNCHRONOUS)
* @param {number} lineNumber - Line number (1-based)
* @returns {LineOperationResult|null} - Line info or null if not found
*/
getLineInfo(lineNumber: number): LineOperationResult | null;
/**
* Get information about multiple lines at once (SYNCHRONOUS)
* @param {number} startLine - Start line number (1-based, inclusive)
* @param {number} endLine - End line number (1-based, inclusive)
* @returns {LineOperationResult[]} - Array of line info
*/
getMultipleLines(startLine: number, endLine: number): LineOperationResult[];
/**
* Convert virtual byte address to line number (SYNCHRONOUS)
* @param {number} virtualAddress - Virtual buffer address
* @returns {number} - Line number (1-based) or 0 if invalid address
*/
getLineNumberFromAddress(virtualAddress: number): number;
/**
* Convert line/character position to absolute byte position (SYNCHRONOUS)
* @param {Object} pos - {line, character} (both 1-based, character = byte offset in line)
* @returns {number} - Absolute byte position
*/
lineCharToBytePosition(pos: Object): number;
/**
* Convert absolute byte position to line/character position (SYNCHRONOUS)
* @param {number} bytePos - Absolute byte position
* @returns {Object} - {line, character} (both 1-based, character = byte offset in line + 1)
*/
byteToLineCharPosition(bytePos: number): Object;
/**
* Get memory usage statistics
* @returns {Object} - Memory usage info
*/
getMemoryStats(): Object;
}
/**
* @typedef {Array<string|number>} MarkTuple
* @property {string} 0 - The name of the mark.
* @property {number} 1 - The absolute address of the mark.
*/
/**
* @typedef {Array<string|number>} RelativeMarkTuple
* @property {string} 0 - The name of the mark.
* @property {number} 1 - The relative address of the mark.
*/
/**
* Represents the result of line-related operations
*/
export class LineOperationResult {
constructor(lineNumber: any, byteStart: any, byteEnd: any, marks?: any[], isExact?: boolean);
lineNumber: any;
byteStart: any;
byteEnd: any;
length: number;
marks: any[];
isExact: boolean;
}
/**
* Represents extracted content with marks
*/
export class ExtractedContent {
constructor(data: any, marks?: any[]);
data: any;
marks: any[];
}
//# sourceMappingURL=line-marks-manager.d.ts.map