本文整理汇总了TypeScript中@typewriter/editor.Delta.diff方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Delta.diff方法的具体用法?TypeScript Delta.diff怎么用?TypeScript Delta.diff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@typewriter/editor.Delta
的用法示例。
在下文中一共展示了Delta.diff方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: record
function record(change: Delta, contents: Delta, oldContents: Delta, selection: Selection, oldSelection: Selection) {
const timestamp = Date.now();
const action = getAction(change);
stack.redo.length = 0;
let undoChange = contents.diff(oldContents);
// Break combining if actions are different (e.g. a delete then an insert should break it)
if (!action || lastAction !== action) cutoff();
lastAction = action;
if (lastRecorded && (!options.delay || lastRecorded + options.delay > timestamp) && stack.undo.length > 0) {
// Combine with the last change
const entry = stack.undo.pop();
oldSelection = entry.undoSelection;
undoChange = undoChange.compose(entry.undo);
change = entry.redo.compose(change);
} else {
lastRecorded = timestamp;
}
stack.undo.push({
redo: change,
undo: undoChange,
redoSelection: selection,
undoSelection: oldSelection,
});
if (stack.undo.length > options.maxStack) {
stack.undo.shift();
}
}