完善韩泰 EOT 标注编辑器并更新标注规范与项目资料
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
export interface EditHistory<T> { past: T[]; present: T; future: T[] }
|
||||
const LIMIT = 40;
|
||||
|
||||
export function createEditHistory<T>(present: T): EditHistory<T> {
|
||||
return { past: [], present, future: [] };
|
||||
}
|
||||
|
||||
export function commitEdit<T>(history: EditHistory<T>, present: T): EditHistory<T> {
|
||||
if (present === history.present) return history;
|
||||
return { past: [...history.past, history.present].slice(-LIMIT), present, future: [] };
|
||||
}
|
||||
|
||||
export function undoEdit<T>(history: EditHistory<T>): EditHistory<T> {
|
||||
if (!history.past.length) return history;
|
||||
return { past: history.past.slice(0, -1), present: history.past.at(-1)!, future: [history.present, ...history.future] };
|
||||
}
|
||||
|
||||
export function redoEdit<T>(history: EditHistory<T>): EditHistory<T> {
|
||||
if (!history.future.length) return history;
|
||||
return { past: [...history.past, history.present].slice(-LIMIT), present: history.future[0], future: history.future.slice(1) };
|
||||
}
|
||||
Reference in New Issue
Block a user