shahnevis-core
Version:
**Shahnevis Core** is a lightweight and flexible library for building custom code editors. It provides essential features like syntax highlighting, a minimap, multi-cursor support, line numbering, and plugin management. This library is framework-agnostic,
38 lines (37 loc) • 1.41 kB
JavaScript
import { saveState as _saveState, debounceSaveState as _debounceSaveState, undo as _undo, redo as _redo, handleUndoRedo as handleUndoRedoAction } from "../utils/stackManager";
/**
* Factory to create an isolated history manager for each editor instance.
* @param {number} maxSize - Maximum number of history entries to keep.
*/
export function createHistoryManager() {
var maxSize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;
var manager = {
undoStack: [],
redoStack: [],
isUndoingOrRedoing: false,
maxHistory: maxSize,
debounceTimeout: null
};
return {
/** Snapshot the current state */
saveState: function saveState(editor, foldingUtils) {
return _saveState(manager, editor, foldingUtils, maxSize);
},
/** Debounced snapshot */
debounceSaveState: function debounceSaveState(editor, foldingUtils) {
return _debounceSaveState(manager, editor, foldingUtils);
},
/** Undo action */
undo: function undo(editor, foldingUtils) {
return _undo(manager, editor, foldingUtils);
},
/** Redo action */
redo: function redo(editor, foldingUtils) {
return _redo(manager, editor, foldingUtils);
},
/** Keydown handler for undo/redo */
handleUndoRedo: function handleUndoRedo(e, editor, foldingUtils) {
return handleUndoRedoAction(manager, e, editor, foldingUtils);
}
};
}