LPXXX text undos
authorBill Erickson <berickxx@gmail.com>
Mon, 2 Dec 2019 23:08:58 +0000 (18:08 -0500)
committerBill Erickson <berickxx@gmail.com>
Fri, 6 Dec 2019 15:37:03 +0000 (10:37 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.ts
Open-ILS/src/eg2/src/app/staff/share/marc-edit/editor-context.ts

index 33209e6..9b2c98b 100644 (file)
@@ -40,7 +40,10 @@ export class EditableContentComponent
     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;
@@ -116,7 +119,7 @@ export class EditableContentComponent
 
     setupFieldType() {
         const content = this.getContent();
-        this.initialContent = content;
+        this.undoBackToContent = content;
 
         switch (this.fieldType) {
             case 'ldr':
@@ -231,15 +234,15 @@ export class EditableContentComponent
             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) {
@@ -252,7 +255,17 @@ export class EditableContentComponent
         }
     }
 
-    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
@@ -393,6 +406,13 @@ export class EditableContentComponent
                 }
                 break;
 
+            case 'y': 
+                if (evt.ctrlKey) { // redo
+                    this.context.requestRedo();
+                    evt.preventDefault();
+                }
+                break;
+
             case 'z': 
                 if (evt.ctrlKey) { // undo
                     this.context.requestUndo();
index c99f934..f4f6c12 100644 (file)
@@ -77,6 +77,14 @@ export class MarcEditContext {
         }
     }
 
+    requestRedo() {
+        const redo = this.redoStack.shift();
+        if (redo) {
+            this.redoRequest.emit(redo);
+            this.requestFieldFocus(redo.position);
+        }
+    }
+
     getFieldOffset(fieldId: number): number {
         for (let idx = 0; idx < this.record.fields.length; idx++) {
             if (this.record.fields[idx].fieldId === fieldId) {