From b24e6ae48f25c9cc290e9420efc9ebe60809ba96 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 2 Dec 2019 18:08:58 -0500 Subject: [PATCH] LPXXX text undos Signed-off-by: Bill Erickson --- .../share/marc-edit/editable-content.component.ts | 30 ++++++++++++++++++---- .../app/staff/share/marc-edit/editor-context.ts | 8 ++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.ts b/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.ts index 33209e69cc..9b2c98bb3f 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.ts @@ -40,7 +40,10 @@ export class EditableContentComponent randId = Math.floor(Math.random() * 100000); editInput: any; // or
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(); diff --git a/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editor-context.ts b/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editor-context.ts index c99f934f36..f4f6c1281a 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editor-context.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editor-context.ts @@ -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) { -- 2.11.0