char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
521a64cd0
char/aliceai-t5-moe
1/** 2* Source-space undo/redo history for the ChatFormInputRich, whose 3* imperative DOM rebuilds destroy the browser's native undo stack. 4* Entries record the state BEFORE an edit; edits within `groupWindowMs` 5* extend the open group so a typing burst undoes as a unit, while 6* structural edits (paste, mention insert, clear) pass `newGroup`. 7*/ 8 9export interface SourceHistoryEntry { 10value :string ; 11caret :number ; 12} 13 14export class SourceHistory { 15private lastPush = 0 ; 16private redoStack :SourceHistoryEntry [] = []; 17private undoStack :SourceHistoryEntry [] = []; 18 19constructor ( 20private limit = 100 , 21private groupWindowMs = 800 22) {} 23 24push ( entry :SourceHistoryEntry , now :number , newGroup = false ) :void { 25if ( newGroup || now - this . lastPush >= this . groupWindowMs || this . undoStack . length === 0 ) { 26this . undoStack . push ( entry ); 27 28if ( this . undoStack . length > this . limit ) this . undoStack . shift (); 29} 30 31this . lastPush = now ; 32this . redoStack = []; 33} 34 35redo ( current :SourceHistoryEntry ) :SourceHistoryEntry | null { 36const entry = this . redoStack . pop (); 37 38if ( ! entry ) return null ; 39 40this . undoStack . push ( current ); 41this . lastPush = 0 ; 42 43return entry ; 44} 45 46undo ( current :SourceHistoryEntry ) :SourceHistoryEntry | null { 47const entry = this . undoStack . pop (); 48 49if ( ! entry ) return null ; 50 51this . redoStack . push ( current ); 52this . lastPush = 0 ; // the next edit after an undo starts a new group 53 54return entry ; 55} 56}