randId = Math.floor(Math.random() * 100000);
editInput: any; // <input/> or <div contenteditable/>
maxLength: number = null;
- initialContent: string; // TODO set me on blur as well
+
+ // Track the load-time content so we know what text value to
+ // track on our undo stack.
+ undoBackToContent: string;
focusSub: Subscription;
undoSub: Subscription;
setupFieldType() {
const content = this.getContent();
- this.initialContent = content;
+ this.undoBackToContent = content;
switch (this.fieldType) {
case 'ldr':
return;
}
- // Track the initial content since that's what we would undo to.
const undo = {
- textContent: this.initialContent,
+ textContent: this.undoBackToContent,
position: this.context.lastFocused
};
this.context.undoStack.unshift(undo);
}
+ // Apply the undo action and track it as a redo
processUndo(undo: UndoRedoAction) {
if (undo.textContent !== undefined) {
}
}
- processRedo(undo: UndoRedoAction) {
+ // Apply the redo action and track it as an undo
+ processRedo(redo: UndoRedoAction) {
+
+ if (redo.textContent !== undefined) {
+ // redoing a text change
+ const undoContent = this.getContent();
+ this.setContent(redo.textContent, true, true);
+
+ redo.textContent = undoContent;
+ this.context.undoStack.unshift(redo);
+ }
}
// Propagate editable div content into our record
}
break;
+ case 'y':
+ if (evt.ctrlKey) { // redo
+ this.context.requestRedo();
+ evt.preventDefault();
+ }
+ break;
+
case 'z':
if (evt.ctrlKey) { // undo
this.context.requestUndo();